@pipedream/streak 0.0.1

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.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2020 Pipedream, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@pipedream/streak",
3
+ "version": "0.0.1",
4
+ "description": "Pipedream Streak Components",
5
+ "main": "streak.app.mjs",
6
+ "keywords": [
7
+ "pipedream",
8
+ "streak"
9
+ ],
10
+ "homepage": "https://pipedream.com/apps/streak",
11
+ "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
+ "license": "MIT",
13
+ "dependencies": {
14
+ "@pipedream/platform": "^1.1.1"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ }
19
+ }
@@ -0,0 +1,33 @@
1
+ import common from "../common/pipeline-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "streak-box-changed-pipeline",
6
+ name: "Box Changed Pipeline (Instant)",
7
+ description: "Emit new event when a box changes pipelines.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getHistoricalEvents(limit) {
14
+ return this.streak.listBoxes({
15
+ pipelineId: this.pipelineId,
16
+ params: {
17
+ limit,
18
+ sortBy: "lastUpdatedTimestamp",
19
+ },
20
+ });
21
+ },
22
+ getEventType() {
23
+ return "BOX_CHANGE_PIPELINE";
24
+ },
25
+ generateMeta(box) {
26
+ return {
27
+ id: box.lastUpdatedTimestamp,
28
+ summary: box.name,
29
+ ts: box.lastUpdatedTimestamp,
30
+ };
31
+ },
32
+ },
33
+ };
@@ -0,0 +1,33 @@
1
+ import common from "../common/pipeline-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "streak-box-changed-stage",
6
+ name: "Box Changed Stage (Instant)",
7
+ description: "Emit new event when a box's stage is updated in a pipeline.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getHistoricalEvents(limit) {
14
+ return this.streak.listBoxes({
15
+ pipelineId: this.pipelineId,
16
+ params: {
17
+ limit,
18
+ sortBy: "lastUpdatedTimestamp",
19
+ },
20
+ });
21
+ },
22
+ getEventType() {
23
+ return "BOX_CHANGE_STAGE";
24
+ },
25
+ generateMeta(box) {
26
+ return {
27
+ id: box.lastUpdatedTimestamp,
28
+ summary: box.name,
29
+ ts: box.lastUpdatedTimestamp,
30
+ };
31
+ },
32
+ },
33
+ };
@@ -0,0 +1,57 @@
1
+ import streak from "../../streak.app.mjs";
2
+
3
+ export default {
4
+ props: {
5
+ streak,
6
+ db: "$.service.db",
7
+ http: "$.interface.http",
8
+ pipelineId: {
9
+ propDefinition: [
10
+ streak,
11
+ "pipelineId",
12
+ ],
13
+ },
14
+ },
15
+ hooks: {
16
+ async deploy() {
17
+ const events = await this.getHistoricalEvents(25);
18
+ if (!events || events.length === 0) {
19
+ return;
20
+ }
21
+ for (const item of events) {
22
+ const meta = this.generateMeta(item);
23
+ this.$emit(item, meta);
24
+ }
25
+ },
26
+ async deactivate() {
27
+ const hookId = this._getHookId();
28
+ await this.streak.deleteWebhook({
29
+ id: hookId,
30
+ });
31
+ },
32
+ },
33
+ methods: {
34
+ _getHookId() {
35
+ return this.db.get("hookId");
36
+ },
37
+ _setHookId(hookId) {
38
+ this.db.set("hookId", hookId);
39
+ },
40
+ shortenKey(key) {
41
+ return key.slice(-72);
42
+ },
43
+ getHistoricalEvents() {
44
+ throw new Error("getHistoricalEvents is not implemented");
45
+ },
46
+ generateMeta() {
47
+ throw new Error("generateMeta is not implemented");
48
+ },
49
+ },
50
+ async run(event) {
51
+ const { body } = event;
52
+ for (const item of body) {
53
+ const meta = this.generateMeta(item);
54
+ this.$emit(item, meta);
55
+ }
56
+ },
57
+ };
@@ -0,0 +1,20 @@
1
+ import common from "./base.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ hooks: {
6
+ ...common.hooks,
7
+ async activate() {
8
+ const { key } = await this.streak.createWebhook({
9
+ params: {
10
+ pipelineKey: this.pipelineId,
11
+ },
12
+ data: {
13
+ targetUrl: this.http.endpoint,
14
+ event: this.getEventType(),
15
+ },
16
+ });
17
+ this._setHookId(key);
18
+ },
19
+ },
20
+ };
@@ -0,0 +1,63 @@
1
+ import common from "./base.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ props: {
6
+ ...common.props,
7
+ teamId: {
8
+ propDefinition: [
9
+ common.props.streak,
10
+ "teamId",
11
+ ],
12
+ },
13
+ },
14
+ hooks: {
15
+ ...common.hooks,
16
+ async activate() {
17
+ const { key } = await this.streak.createWebhook({
18
+ params: {
19
+ teamKey: this.teamId,
20
+ },
21
+ data: {
22
+ targetUrl: this.http.endpoint,
23
+ event: this.getEventType(),
24
+ },
25
+ });
26
+ this._setHookId(key);
27
+ },
28
+ },
29
+ methods: {
30
+ ...common.methods,
31
+ async getContactsInPipeline(limit) {
32
+ const boxes = await this.streak.listBoxes({
33
+ pipelineId: this.pipelineId,
34
+ params: {
35
+ limit,
36
+ sortBy: "lastUpdatedTimestamp",
37
+ },
38
+ });
39
+ const contactIds = [];
40
+ for (const box of boxes) {
41
+ if (!box.contacts) {
42
+ continue;
43
+ }
44
+ const contactKeys = box.contacts.map((contact) => contact.key);
45
+ if (contactKeys?.length > 0) {
46
+ contactIds.push(...contactKeys);
47
+ }
48
+ }
49
+ const contacts = [];
50
+ for (const contactId of contactIds) {
51
+ const contact = await this.streak.getContact({
52
+ contactId,
53
+ });
54
+ contacts.push(contact);
55
+ if (contacts.length >= limit) {
56
+ contacts.length = limit;
57
+ break;
58
+ }
59
+ }
60
+ return contacts;
61
+ },
62
+ },
63
+ };
@@ -0,0 +1,33 @@
1
+ import common from "../common/pipeline-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "streak-new-box",
6
+ name: "New Box (Instant)",
7
+ description: "Emit new event when a new box is created in a pipeline.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getHistoricalEvents(limit) {
14
+ return this.streak.listBoxes({
15
+ pipelineId: this.pipelineId,
16
+ params: {
17
+ limit,
18
+ sortBy: "creationTimestamp",
19
+ },
20
+ });
21
+ },
22
+ getEventType() {
23
+ return "BOX_CREATE";
24
+ },
25
+ generateMeta(box) {
26
+ return {
27
+ id: this.shortenKey(box.key),
28
+ summary: box.name,
29
+ ts: box.creationTimestamp,
30
+ };
31
+ },
32
+ },
33
+ };
@@ -0,0 +1,45 @@
1
+ import common from "../common/pipeline-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "streak-new-comment",
6
+ name: "New Comment (Instant)",
7
+ description: "Emit new event when a new comment is created within a pipeline.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getHistoricalEvents(limit) {
14
+ const boxes = await this.streak.listBoxes({
15
+ pipelineId: this.pipelineId,
16
+ params: {
17
+ limit,
18
+ sortBy: "lastUpdatedTimestamp",
19
+ },
20
+ });
21
+ const comments = [];
22
+ for (const box of boxes) {
23
+ const { results } = await this.streak.listComments({
24
+ boxId: box.key,
25
+ });
26
+ comments.push(...results);
27
+ if (comments.length >= limit) {
28
+ comments.length = limit;
29
+ break;
30
+ }
31
+ }
32
+ return comments;
33
+ },
34
+ getEventType() {
35
+ return "COMMENT_CREATE";
36
+ },
37
+ generateMeta(comment) {
38
+ return {
39
+ id: this.shortenKey(comment.key),
40
+ summary: comment.message,
41
+ ts: comment.timestamp,
42
+ };
43
+ },
44
+ },
45
+ };
@@ -0,0 +1,27 @@
1
+ import common from "../common/team-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "streak-new-contact",
6
+ name: "New Contact (Instant)",
7
+ description: "Emit new event when a new contact is created within a team.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getHistoricalEvents(limit) {
14
+ return this.getContactsInPipeline(limit);
15
+ },
16
+ getEventType() {
17
+ return "CONTACT_CREATE";
18
+ },
19
+ generateMeta(contact) {
20
+ return {
21
+ id: this.shortenKey(contact.key),
22
+ summary: contact.emailAddresses[0],
23
+ ts: contact.creationDate,
24
+ };
25
+ },
26
+ },
27
+ };
@@ -0,0 +1,34 @@
1
+ import common from "../common/pipeline-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "streak-new-email-on-box",
6
+ name: "New Email on Box (Instant)",
7
+ description: "Emit new event when an email is added to a box in a pipeline.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getHistoricalEvents(limit) {
14
+ const boxes = await this.streak.listBoxes({
15
+ pipelineId: this.pipelineId,
16
+ params: {
17
+ limit,
18
+ sortBy: "lastUpdatedTimestamp",
19
+ },
20
+ });
21
+ return boxes.filter((box) => box?.emailAddresses.length > 0);
22
+ },
23
+ getEventType() {
24
+ return "BOX_NEW_EMAIL_ADDRESS";
25
+ },
26
+ generateMeta(box) {
27
+ return {
28
+ id: box.lastUpdatedTimestamp,
29
+ summary: box.name,
30
+ ts: box.lastUpdatedTimestamp,
31
+ };
32
+ },
33
+ },
34
+ };
@@ -0,0 +1,45 @@
1
+ import common from "../common/pipeline-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "streak-new-task",
6
+ name: "New Task (Instant)",
7
+ description: "Emit new event when a new task is created in a pipeline.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getHistoricalEvents(limit) {
14
+ const boxes = await this.streak.listBoxes({
15
+ pipelineId: this.pipelineId,
16
+ params: {
17
+ limit,
18
+ sortBy: "lastUpdatedTimestamp",
19
+ },
20
+ });
21
+ const tasks = [];
22
+ for (const box of boxes) {
23
+ const { results } = await this.streak.listTasks({
24
+ boxId: box.key,
25
+ });
26
+ tasks.push(...results);
27
+ if (tasks.length >= limit) {
28
+ tasks.length = limit;
29
+ break;
30
+ }
31
+ }
32
+ return tasks;
33
+ },
34
+ getEventType() {
35
+ return "TASK_CREATE";
36
+ },
37
+ generateMeta(task) {
38
+ return {
39
+ id: this.shortenKey(task.key),
40
+ summary: task.text,
41
+ ts: task.creationDate,
42
+ };
43
+ },
44
+ },
45
+ };
@@ -0,0 +1,46 @@
1
+ import common from "../common/pipeline-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "streak-new-task-due",
6
+ name: "New Task Due (Instant)",
7
+ description: "Emit new event when a new task is created in a pipeline.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getHistoricalEvents(limit) {
14
+ const boxes = await this.streak.listBoxes({
15
+ pipelineId: this.pipelineId,
16
+ params: {
17
+ limit,
18
+ sortBy: "lastUpdatedTimestamp",
19
+ },
20
+ });
21
+ const tasks = [];
22
+ for (const box of boxes) {
23
+ const { results } = await this.streak.listTasks({
24
+ boxId: box.key,
25
+ });
26
+ const pastDueTasks = results.filter((task) => task?.reminderStatus === "REMINDED");
27
+ tasks.push(...pastDueTasks);
28
+ if (tasks.length >= limit) {
29
+ tasks.length = limit;
30
+ break;
31
+ }
32
+ }
33
+ return tasks;
34
+ },
35
+ getEventType() {
36
+ return "TASK_DUE";
37
+ },
38
+ generateMeta(task) {
39
+ return {
40
+ id: this.shortenKey(task.key),
41
+ summary: task.text,
42
+ ts: task.lastStatusChangeDate,
43
+ };
44
+ },
45
+ },
46
+ };
@@ -0,0 +1,46 @@
1
+ import common from "../common/pipeline-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "streak-task-completed",
6
+ name: "Task Completed (Instant)",
7
+ description: "Emit new event when a task is completed in a pipeline.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getHistoricalEvents(limit) {
14
+ const boxes = await this.streak.listBoxes({
15
+ pipelineId: this.pipelineId,
16
+ params: {
17
+ limit,
18
+ sortBy: "lastUpdatedTimestamp",
19
+ },
20
+ });
21
+ const tasks = [];
22
+ for (const box of boxes) {
23
+ const { results } = await this.streak.listTasks({
24
+ boxId: box.key,
25
+ });
26
+ const completedTasks = results.filter((task) => task?.status === "DONE");
27
+ tasks.push(...completedTasks);
28
+ if (tasks.length >= limit) {
29
+ tasks.length = limit;
30
+ break;
31
+ }
32
+ }
33
+ return tasks;
34
+ },
35
+ getEventType() {
36
+ return "TASK_COMPLETE";
37
+ },
38
+ generateMeta(task) {
39
+ return {
40
+ id: this.shortenKey(task.key),
41
+ summary: task.text,
42
+ ts: task.lastStatusChangeDate,
43
+ };
44
+ },
45
+ },
46
+ };
@@ -0,0 +1,33 @@
1
+ import common from "../common/pipeline-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "streak-updated-box",
6
+ name: "Updated Box (Instant)",
7
+ description: "Emit new event when a box is updated in a pipeline.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getHistoricalEvents(limit) {
14
+ return this.streak.listBoxes({
15
+ pipelineId: this.pipelineId,
16
+ params: {
17
+ limit,
18
+ sortBy: "lastUpdatedTimestamp",
19
+ },
20
+ });
21
+ },
22
+ getEventType() {
23
+ return "BOX_EDIT";
24
+ },
25
+ generateMeta(box) {
26
+ return {
27
+ id: box.lastUpdatedTimestamp,
28
+ summary: box.name,
29
+ ts: box.lastUpdatedTimestamp,
30
+ };
31
+ },
32
+ },
33
+ };
@@ -0,0 +1,27 @@
1
+ import common from "../common/team-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "streak-updated-contact",
6
+ name: "Updated Contact (Instant)",
7
+ description: "Emit new event when a contact is updated within a team.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getHistoricalEvents(limit) {
14
+ return this.getContactsInPipeline(limit);
15
+ },
16
+ getEventType() {
17
+ return "CONTACT_UPDATE";
18
+ },
19
+ generateMeta(contact) {
20
+ return {
21
+ id: contact.lastSavedTimestamp,
22
+ summary: contact.emailAddresses[0],
23
+ ts: contact.lastSavedTimestamp,
24
+ };
25
+ },
26
+ },
27
+ };
package/streak.app.mjs ADDED
@@ -0,0 +1,125 @@
1
+ import { axios } from "@pipedream/platform";
2
+
3
+ export default {
4
+ type: "app",
5
+ app: "streak",
6
+ propDefinitions: {
7
+ pipelineId: {
8
+ type: "string",
9
+ label: "Pipeline",
10
+ description: "Filter by pipeline",
11
+ async options() {
12
+ const pipelines = await this.listPipelines();
13
+ return pipelines.map((pipeline) => ({
14
+ label: pipeline.name,
15
+ value: pipeline.key,
16
+ }));
17
+ },
18
+ },
19
+ teamId: {
20
+ type: "string",
21
+ label: "Team",
22
+ description: "Filter by team",
23
+ async options() {
24
+ const { results } = await this.listTeams();
25
+ return results.map((team) => ({
26
+ label: team.name,
27
+ value: team.key,
28
+ }));
29
+ },
30
+ },
31
+ },
32
+ methods: {
33
+ _getBaseUrl() {
34
+ return "https://www.streak.com/api/";
35
+ },
36
+ _getAuth() {
37
+ return {
38
+ username: this.$auth.api_key,
39
+ };
40
+ },
41
+ async _makeRequest(args = {}) {
42
+ const {
43
+ method = "GET",
44
+ path,
45
+ $ = this,
46
+ ...otherArgs
47
+ } = args;
48
+ const config = {
49
+ method,
50
+ url: `${this._getBaseUrl()}${path}`,
51
+ auth: this._getAuth(),
52
+ ...otherArgs,
53
+ };
54
+ return axios($, config);
55
+ },
56
+ async createWebhook(args = {}) {
57
+ return this._makeRequest({
58
+ method: "POST",
59
+ path: "v2/webhooks",
60
+ ...args,
61
+ });
62
+ },
63
+ async deleteWebhook({
64
+ id, ...args
65
+ }) {
66
+ return this._makeRequest({
67
+ method: "DELETE",
68
+ path: `v2/webhooks/${id}`,
69
+ ...args,
70
+ });
71
+ },
72
+ async getContact({
73
+ contactId, ...args
74
+ }) {
75
+ return this._makeRequest({
76
+ path: `v2/contacts/${contactId}`,
77
+ ...args,
78
+ });
79
+ },
80
+ async listPipelines(args = {}) {
81
+ return this._makeRequest({
82
+ path: "v1/pipelines",
83
+ ...args,
84
+ });
85
+ },
86
+ async listTeams(args = {}) {
87
+ return this._makeRequest({
88
+ path: "v2/users/me/teams",
89
+ ...args,
90
+ });
91
+ },
92
+ async listBoxes({
93
+ pipelineId, ...args
94
+ }) {
95
+ return this._makeRequest({
96
+ path: `v1/pipelines/${pipelineId}/boxes`,
97
+ ...args,
98
+ });
99
+ },
100
+ async listComments({
101
+ boxId, ...args
102
+ }) {
103
+ return this._makeRequest({
104
+ path: `v2/boxes/${boxId}/comments`,
105
+ ...args,
106
+ });
107
+ },
108
+ async listTasks({
109
+ boxId, ...args
110
+ }) {
111
+ return this._makeRequest({
112
+ path: `v2/boxes/${boxId}/tasks`,
113
+ ...args,
114
+ });
115
+ },
116
+ async listContacts({
117
+ boxId, ...args
118
+ }) {
119
+ return this._makeRequest({
120
+ path: `v1/boxes/${boxId}`,
121
+ ...args,
122
+ });
123
+ },
124
+ },
125
+ };