Skip to content

Commit 6844354

Browse files
committed
refactoring sources - wip
1 parent 9bbe06a commit 6844354

File tree

15 files changed

+75
-79
lines changed

15 files changed

+75
-79
lines changed

components/trello/sources/card-archived/card-archived.mjs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import common from "../common/common-webhook.mjs";
33
export default {
44
...common,
55
key: "trello-card-archived",
6-
name: "Card Archived (Instant)",
6+
name: "Card Archived (Instant)", /* eslint-disable-line pipedream/source-name */
77
description: "Emit new event for each card archived.",
88
version: "0.1.0",
99
type: "source",
@@ -28,20 +28,10 @@ export default {
2828
},
2929
methods: {
3030
...common.methods,
31-
getFilteredCards({
32-
boardId, ...args
33-
} = {}) {
34-
return this.app._makeRequest({
35-
path: `/boards/${boardId}/cards`,
36-
...args,
37-
});
38-
},
3931
async getSampleEvents() {
40-
const cards = await this.getFilteredCards({
32+
const cards = await this.app.getFilteredCards({
4133
boardId: this.board,
42-
params: {
43-
filter: "closed",
44-
},
34+
filter: "closed",
4535
});
4636
return {
4737
sampleEvents: cards,
@@ -61,8 +51,7 @@ export default {
6151
isRelevant({ result: card }) {
6252
return (
6353
(!this.board || this.board === card.idBoard) &&
64-
(!this.lists ||
65-
this.lists.length === 0 ||
54+
(!this.lists?.length ||
6655
this.lists.includes(card.idList))
6756
);
6857
},

components/trello/sources/card-moved/card-moved.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import common from "../common/common-webhook.mjs";
33
export default {
44
...common,
55
key: "trello-card-moved",
6-
name: "Card Moved (Instant)",
6+
name: "Card Moved (Instant)", /* eslint-disable-line pipedream/source-name */
77
description: "Emit new event each time a card is moved to a list.",
88
version: "0.1.0",
99
type: "source",
@@ -28,7 +28,7 @@ export default {
2828
methods: {
2929
...common.methods,
3030
async getSampleEvents() {
31-
const cards = this.lists && this.lists.length > 0
31+
const cards = this.lists?.length > 0
3232
? await this.app.getCardsInList({
3333
listId: this.lists[0],
3434
})
@@ -67,8 +67,7 @@ export default {
6767

6868
return (
6969
(!this.board || this.board === card.idBoard) &&
70-
(!this.lists ||
71-
this.lists.length === 0 ||
70+
(!this.lists?.length ||
7271
this.lists.includes(listIdAfter) ||
7372
this.lists.includes(listIdBefore))
7473
);
@@ -77,6 +76,7 @@ export default {
7776
id, name,
7877
}) {
7978
const listAfter = this._getListAfter();
79+
name = name || id;
8080
const summary = listAfter
8181
? `${name} - moved to ${listAfter}`
8282
: name;

components/trello/sources/card-updates/card-updates.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import common from "../common/common-webhook.mjs";
33
export default {
44
...common,
55
key: "trello-card-updates",
6-
name: "Card Updates (Instant)",
6+
name: "Card Updates (Instant)", /* eslint-disable-line pipedream/source-name */
77
description: "Emit new event for each update to a Trello card.",
88
version: "0.1.0",
99
type: "source",
@@ -35,7 +35,7 @@ export default {
3535
...common.methods,
3636
async getSampleEvents() {
3737
let cards = [];
38-
if (this.cards && this.cards.length > 0) {
38+
if (this.cards?.length > 0) {
3939
for (const cardId of this.cards) {
4040
const card = await this.app.getCard({
4141
cardId,
@@ -74,7 +74,7 @@ export default {
7474
isRelevant({ result: card }) {
7575
return (
7676
(!this.board || this.board === card.idBoard) &&
77-
(!this.cards || this.cards.length === 0 || this.cards.includes(card.id))
77+
(!this.cards?.length || this.cards.includes(card.id))
7878
);
7979
},
8080
},

components/trello/sources/common/common-board-based.mjs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
],
1515
},
1616
onlyEventsRelatedWithAuthenticatedUser: {
17-
label: "Only Events Related With Me",
17+
label: "Only Events Related To Me",
1818
description: "Only will emit events from the cards related with the authenticated user",
1919
type: "boolean",
2020
default: false,
@@ -36,15 +36,11 @@ export default {
3636
memberId: "me",
3737
});
3838

39-
if (
39+
return !(
4040
this.onlyEventsRelatedWithAuthenticatedUser &&
4141
result?.idMembers?.length &&
4242
!result.idMembers.includes(member.id)
43-
) {
44-
return false;
45-
}
46-
47-
return true;
43+
);
4844
},
4945
},
5046
};

components/trello/sources/common/common-webhook.mjs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@ export default {
2828
callbackURL: this.http.endpoint,
2929
},
3030
});
31-
this.db.set("hookId", id);
31+
this._setHookId(id);
3232
},
3333
async deactivate() {
34-
const hookId = this.db.get("hookId");
35-
await this.deleteHook({
36-
hookId,
37-
});
34+
const hookId = this._getHookId();
35+
if (hookId) {
36+
await this.deleteHook({
37+
hookId,
38+
});
39+
}
3840
},
3941
},
4042
methods: {
4143
...common.methods,
44+
_getHookId() {
45+
return this.db.get("hookId");
46+
},
47+
_setHookId(hookId) {
48+
this.db.set("hookId", hookId);
49+
},
4250
getBase64Digest(data) {
4351
const { secret } = this.app.getToken();
4452
return createHmac("sha1", secret)
@@ -57,7 +65,6 @@ export default {
5765
createHook(args = {}) {
5866
return this.app.post({
5967
...args,
60-
debug: true,
6168
path: "/webhooks/",
6269
});
6370
},
@@ -66,7 +73,6 @@ export default {
6673
} = {}) {
6774
return this.app.delete({
6875
...args,
69-
debug: true,
7076
path: `/webhooks/${hookId}`,
7177
});
7278
},

components/trello/sources/common/common.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ export default {
1313
* @param {string} name - The name of the item of the book.
1414
*/
1515
generateMeta({
16-
id, name: summary,
16+
id, name,
1717
}) {
1818
return {
1919
id,
20-
summary,
20+
summary: name || `${id}`,
2121
ts: Date.now(),
2222
};
2323
},

components/trello/sources/custom-webhook-events/custom-webhook-events.mjs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import events from "../common/events.mjs";
44
export default {
55
...common,
66
key: "trello-custom-webhook-events",
7-
name: "Custom Webhook Events (Instant)",
7+
name: "Custom Webhook Events (Instant)", /* eslint-disable-line pipedream/source-name */
88
description: "Emit new events for activity matching a board, event types, lists and/or cards.",
99
version: "0.1.0",
1010
type: "source",
@@ -60,16 +60,8 @@ export default {
6060
},
6161
methods: {
6262
...common.methods,
63-
getCardList({
64-
cardId, ...args
65-
} = {}) {
66-
return this.app._makeRequest({
67-
path: `/cards/${cardId}/list`,
68-
...args,
69-
});
70-
},
7163
async getSampleEvents() {
72-
const eventTypes = this.eventTypes && this.eventTypes.length > 0
64+
const eventTypes = this.eventTypes?.length > 0
7365
? this.eventTypes.join(",")
7466
: null;
7567
const actions = await this.app.getBoardActivity({
@@ -87,8 +79,7 @@ export default {
8779
const eventType = event.body?.action?.type;
8880
return (
8981
(eventType) &&
90-
(!this.eventTypes ||
91-
this.eventTypes.length === 0 ||
82+
(!this.eventTypes?.length ||
9283
this.eventTypes.includes(eventType))
9384
);
9485
},
@@ -106,22 +97,21 @@ export default {
10697
listId = res.id;
10798
}
10899
return (
109-
(!this.lists ||
110-
this.lists.length === 0 ||
100+
(!this.lists?.length ||
111101
!listId ||
112102
this.lists.includes(listId)) &&
113-
(!this.cards || this.cards.length === 0 || !cardId || this.cards.includes(cardId))
103+
(!this.cards?.length || !cardId || this.cards.includes(cardId))
114104
);
115105
},
116106
generateMeta({ action }) {
117107
const {
118108
id,
119-
type: summary,
109+
type,
120110
date,
121111
} = action;
122112
return {
123113
id,
124-
summary,
114+
summary: `New ${type} event`,
125115
ts: Date.parse(date),
126116
};
127117
},

components/trello/sources/new-activity/new-activity.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ export default {
5353
generateMeta({ action }) {
5454
const {
5555
id,
56-
type: summary,
56+
type,
5757
date,
5858
} = action;
5959
return {
6060
id,
61-
summary,
61+
summary: `New ${type} activity`,
6262
ts: Date.parse(date),
6363
};
6464
},

components/trello/sources/new-attachment/new-attachment.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
...common,
55
key: "trello-new-attachment",
66
name: "New Attachment (Instant)",
7-
description: "Emit new event for new attachment on a board.",
7+
description: "Emit new event when a new attachment is added on a board.",
88
version: "0.1.0",
99
type: "source",
1010
props: {

components/trello/sources/new-card/new-card.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default {
3535
methods: {
3636
...common.methods,
3737
async getSampleEvents() {
38-
const cards = this.lists && this.lists.length > 0
38+
const cards = this.lists?.length > 0
3939
? await this.app.getCardsInList({
4040
listId: this.lists[0],
4141
params: {
@@ -70,8 +70,7 @@ export default {
7070
if (this.board && this.board !== card.idBoard) return false;
7171
return (
7272
(!this.board || this.board === card.idBoard) &&
73-
(!this.lists ||
74-
this.lists.length === 0 ||
73+
(!this.lists?.length ||
7574
this.lists.includes(card.idList))
7675
);
7776
},

0 commit comments

Comments
 (0)