@pipedream/trello 0.3.2 → 0.3.5

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.
Files changed (71) hide show
  1. package/actions/add-attachment-to-card-via-url/add-attachment-to-card-via-url.mjs +73 -0
  2. package/actions/add-checklist/add-checklist.mjs +68 -0
  3. package/actions/add-comment/add-comment.mjs +55 -0
  4. package/actions/add-existing-label-to-card/add-existing-label-to-card.mjs +48 -0
  5. package/actions/add-file-as-attachment-via-url/add-file-as-attachment-via-url.mjs +72 -0
  6. package/actions/add-image-attachment/add-image-attachment.mjs +75 -0
  7. package/actions/add-label-to-card/add-label-to-card.mjs +55 -0
  8. package/actions/add-member-to-card/add-member-to-card.mjs +48 -0
  9. package/actions/archive-card/archive-card.mjs +37 -0
  10. package/actions/close-board/close-board.mjs +25 -0
  11. package/actions/common.js +21 -0
  12. package/actions/complete-checklist-item/complete-checklist-item.mjs +49 -0
  13. package/actions/copy-board/copy-board.mjs +174 -0
  14. package/actions/create-board/create-board.mjs +175 -0
  15. package/actions/create-card/create-card.mjs +195 -0
  16. package/actions/create-checklist/create-checklist.mjs +66 -0
  17. package/actions/create-checklist-item/create-checklist-item.mjs +67 -0
  18. package/actions/create-comment-on-card/create-comment-on-card.mjs +42 -0
  19. package/actions/create-label/create-label.mjs +73 -0
  20. package/actions/create-list/create-list.mjs +67 -0
  21. package/actions/delete-checklist/delete-checklist.mjs +46 -0
  22. package/actions/find-labels/find-labels.mjs +44 -0
  23. package/actions/find-list/find-list.mjs +49 -0
  24. package/actions/get-card/get-card.mjs +37 -0
  25. package/actions/get-list/get-list.mjs +32 -0
  26. package/actions/move-card-to-list/move-card-to-list.mjs +53 -0
  27. package/actions/remove-label-from-card/remove-label-from-card.mjs +47 -0
  28. package/actions/rename-list/rename-list.mjs +47 -0
  29. package/actions/search-boards/search-boards.mjs +57 -0
  30. package/actions/search-cards/search-cards.mjs +59 -0
  31. package/actions/search-checklists/search-checklists.mjs +110 -0
  32. package/actions/search-members/search-members.mjs +61 -0
  33. package/actions/update-card/update-card.mjs +165 -0
  34. package/common/events.js +138 -0
  35. package/common/fields.js +50 -0
  36. package/package.json +23 -19
  37. package/sources/board-based.mjs +27 -0
  38. package/sources/card-archived/card-archived.mjs +54 -0
  39. package/sources/card-due-date-reminder/card-due-date-reminder.mjs +80 -0
  40. package/sources/card-moved/card-moved.mjs +84 -0
  41. package/sources/card-updates/card-updates.mjs +60 -0
  42. package/sources/common-polling.mjs +16 -0
  43. package/sources/common-webhook.mjs +90 -0
  44. package/sources/common.js +34 -0
  45. package/sources/custom-webhook-events/custom-webhook-events.mjs +110 -0
  46. package/sources/new-activity/new-activity.mjs +64 -0
  47. package/sources/new-attachment/new-attachment.mjs +60 -0
  48. package/sources/new-board/new-board.mjs +29 -0
  49. package/sources/new-card/new-card.mjs +58 -0
  50. package/sources/new-checklist/new-checklist.mjs +29 -0
  51. package/sources/new-comment-added-to-card/new-comment-added-to-card.mjs +94 -0
  52. package/sources/new-label/new-label.mjs +41 -0
  53. package/sources/new-label-added-to-card/new-label-added-to-card.mjs +138 -0
  54. package/sources/new-list/new-list.mjs +29 -0
  55. package/sources/new-member-on-card/new-member-on-card.mjs +38 -0
  56. package/sources/new-notification/new-notification.mjs +50 -0
  57. package/trello.app.js +647 -145
  58. package/sources/card-archived/card-archived.js +0 -75
  59. package/sources/card-due-date-reminder/card-due-date-reminder.js +0 -65
  60. package/sources/card-moved/card-moved.js +0 -84
  61. package/sources/card-updates/card-updates.js +0 -77
  62. package/sources/custom-webhook-events/custom-webhook-events.js +0 -72
  63. package/sources/new-board/new-board.js +0 -62
  64. package/sources/new-card/new-card.js +0 -77
  65. package/sources/new-checklist/new-checklist.js +0 -74
  66. package/sources/new-comment-added-to-card/new-comment-added-to-card.js +0 -86
  67. package/sources/new-label/new-label.js +0 -73
  68. package/sources/new-label-added-to-card/new-labels-added-to-card.js +0 -85
  69. package/sources/new-list/new-list.js +0 -74
  70. package/sources/new-member-on-card/new-member-on-card.js +0 -75
  71. package/sources/new-notification/new-notification.js +0 -45
package/trello.app.js CHANGED
@@ -1,113 +1,250 @@
1
- const axios = require("axios");
2
- var crypto = require("crypto");
3
- const events = [
4
- { label: "Add Attachment To Card", value: `addAttachmentToCard` },
5
- { label: "Add Checklist To Card", value: `addChecklistToCard` },
6
- { label: "Add Label To Card", value: `addLabelToCard` },
7
- { label: "Add Member To Board", value: `addMemberToBoard` },
8
- { label: "Add Member To Card", value: `addMemberToCard` },
9
- { label: "Comment Card", value: `commentCard` },
10
- {
11
- label: "Convert To Card From Check Item",
12
- value: `convertToCardFromCheckItem`,
13
- },
14
- { label: "Copy Card", value: `copyCard` },
15
- { label: "Create Card", value: `createCard` },
16
- { label: "Create Check Item", value: `createCheckItem` },
17
- { label: "Create Label", value: `createLabel` },
18
- { label: "Create List", value: `createList` },
19
- { label: "Delete Attachment From Card", value: `deleteAttachmentFromCard` },
20
- { label: "Delete Card", value: `deleteCard` },
21
- { label: "Delete Check Item", value: `deleteCheckItem` },
22
- { label: "Delete Comment", value: `deleteComment` },
23
- { label: "Delete Label", value: `deleteLabel` },
24
- { label: "Email Card", value: `emailCard` },
25
- { label: "Move Card From Board", value: `moveCardFromBoard` },
26
- { label: "Move Card To Board", value: `moveCardToBoard` },
27
- { label: "Move List From Board", value: `moveListFromBoard` },
28
- { label: "Move List To Board", value: `moveListToBoard` },
29
- { label: "Remove Checklist From Card", value: `removeChecklistFromCard` },
30
- { label: "Remove Label From Card", value: `removeLabelFromCard` },
31
- { label: "Remove Member From Board", value: `removeMemberFromBoard` },
32
- { label: "Remove Member From Card", value: `removeMemberFromCard` },
33
- { label: "Update Board", value: `updateBoard` },
34
- { label: "Update Card", value: `updateCard` },
35
- { label: "Update Check Item", value: `updateCheckItem` },
36
- {
37
- label: "Update Check Item State On Card",
38
- value: `updateCheckItemStateOnCard`,
39
- },
40
- { label: "Update Checklist", value: `updateChecklist` },
41
- { label: "Update Comment", value: `updateComment` },
42
- { label: "Update Label", value: `updateLabel` },
43
- { label: "Update List", value: `updateList` },
44
- ];
1
+ const { axios } = require("@pipedream/platform");
2
+ const crypto = require("crypto");
3
+ const events = require("./common/events.js");
4
+ const fields = require("./common/fields.js");
5
+ const mime = require("mime");
45
6
 
46
7
  module.exports = {
47
8
  type: "app",
48
9
  app: "trello",
10
+ description: "Pipedream Trello Components",
49
11
  propDefinitions: {
50
- cardIds: {
51
- // after should be array + assume after apps
12
+ cards: {
52
13
  type: "string[]",
53
14
  label: "Cards",
15
+ description: "The Trello cards you wish to select",
54
16
  optional: true,
55
- // options needs to support standardized opts for pagination
56
17
  async options(opts) {
57
- const cards = await this.getCards(opts.boardId);
58
- // XXX short hand where value and label are same value
59
- return cards.map((card) => {
60
- return { label: card.name, value: card.id };
61
- });
18
+ const cards = await this.getCards(opts.board);
19
+ return cards.map((card) => ({
20
+ label: card.name,
21
+ value: card.id,
22
+ }));
62
23
  },
63
24
  },
64
- boardId: {
65
- // after should be array + assume after apps
25
+ board: {
66
26
  type: "string",
67
27
  label: "Board",
68
- // options needs to support standardized opts for pagination
69
- async options(opts) {
70
- const boards = await this.getBoards(this.$auth.oauth_uid);
71
- // XXX short hand where value and label are same value
28
+ description: "The Trello board you wish to select",
29
+ async options() {
30
+ const boards = await this.getBoards();
72
31
  const activeBoards = boards.filter((board) => board.closed === false);
73
- return activeBoards.map((board) => {
74
- return { label: board.name, value: board.id };
75
- });
32
+ return activeBoards.map((board) => ({
33
+ label: board.name,
34
+ value: board.id,
35
+ }));
76
36
  },
77
- // XXX validate
37
+ },
38
+ boardFields: {
39
+ type: "string[]",
40
+ label: "Boards Fields",
41
+ description: "`all` or a list of board [fields](https://developer.atlassian.com/cloud/trello/guides/rest-api/object-definitions/#board-object)",
42
+ options: fields.board,
43
+ default: [
44
+ "name",
45
+ "idOrganization",
46
+ ],
47
+ },
48
+ cardFields: {
49
+ type: "string[]",
50
+ label: "Cards Fields",
51
+ description: "`all` or a list of card [fields](https://developer.atlassian.com/cloud/trello/guides/rest-api/object-definitions/#card-object)",
52
+ options: fields.card,
53
+ default: [
54
+ "all",
55
+ ],
78
56
  },
79
57
  eventTypes: {
80
- // after should be array + assume after apps
81
58
  type: "string[]",
82
59
  label: "Event Types",
83
60
  optional: true,
84
- description:
85
- "Only emit events for the selected event types (e.g., `updateCard`).",
86
- // options needs to support standardized opts for pagination
61
+ description: "Only emit events for the selected event types (e.g., `updateCard`).",
87
62
  options: events,
88
- // XXX validate
89
63
  },
90
- listIds: {
91
- // after should be array + assume after apps
64
+ lists: {
92
65
  type: "string[]",
93
66
  label: "Lists",
67
+ description: "The Trello lists you wish to select",
94
68
  optional: true,
95
- // options needs to support standardized opts for pagination
96
69
  async options(opts) {
97
- const lists = await this.getLists(opts.boardId);
98
- // XXX short hand where value and label are same value
99
- return lists.map((list) => {
100
- return { label: list.name, value: list.id };
101
- });
70
+ const lists = await this.getLists(opts.board);
71
+ return lists.map((list) => ({
72
+ label: list.name,
73
+ value: list.id,
74
+ }));
75
+ },
76
+ },
77
+ query: {
78
+ type: "string",
79
+ label: "Query",
80
+ description: "The search query with a length of 1 to 16384 characters",
81
+ },
82
+ idOrganizations: {
83
+ type: "string[]",
84
+ label: "Organization IDs",
85
+ description: "Specify the organizations to search for boards in",
86
+ async options() {
87
+ const orgs = await this.listOrganizations(this.$auth.oauth_uid);
88
+ return orgs.map((org) => ({
89
+ label: org.name || org.id,
90
+ value: org.id,
91
+ }));
102
92
  },
103
- // XXX validate
93
+ optional: true,
94
+ },
95
+ modelTypes: {
96
+ type: "string",
97
+ label: "Model Types",
98
+ description: "The type or types of Trello objects you want to search. `all` or a comma-separated list of: `actions`, `boards`, `cards`, `members`, `organizations`",
99
+ default: "all",
100
+ },
101
+ partial: {
102
+ type: "boolean",
103
+ label: "Partial Search?",
104
+ description: "Specifying partial to be true means that Trello will search for content that starts with any of the words in `query`. When searching for an object titled \"My Development Status Report\", by default a solution is to search for \"Development\". If partial is enabled, a search for \"dev\" is possible, however, a search for \"velopment\" is not possible.",
105
+ default: false,
106
+ },
107
+ label: {
108
+ type: "string",
109
+ label: "Label",
110
+ description: "The ID of the Label to be added to the card",
111
+ async options(opts) {
112
+ const labels = await this.findLabel(opts.board);
113
+ return labels.map((label) => ({
114
+ label: label.name,
115
+ value: label.id,
116
+ }));
117
+ },
118
+ },
119
+ member: {
120
+ type: "string",
121
+ label: "Member",
122
+ description: "The ID of the Member to be added to the card",
123
+ async options(opts) {
124
+ const members = await this.listMembers(opts.board);
125
+ return members.map((member) => ({
126
+ label: member.fullName,
127
+ value: member.id,
128
+ }));
129
+ },
130
+ },
131
+ checklist: {
132
+ type: "string",
133
+ label: "Checklist",
134
+ description: "The ID of a checklist to copy into the new checklist",
135
+ async options(opts) {
136
+ const {
137
+ board,
138
+ card,
139
+ } = opts;
140
+ const checklists = card ?
141
+ await this.listCardChecklists(card) :
142
+ await this.listBoardChecklists(board);
143
+ return checklists.map((checklist) => ({
144
+ label: checklist.name,
145
+ value: checklist.id,
146
+ }));
147
+ },
148
+ },
149
+ mimeType: {
150
+ type: "string",
151
+ label: "File Attachment Type",
152
+ description: "Not required for URL attachment",
153
+ optional: true,
154
+ options() {
155
+ return Object.values(mime._types);
156
+ },
157
+ },
158
+ name: {
159
+ type: "string",
160
+ label: "Name",
161
+ description: "The name of the attachment",
162
+ optional: true,
163
+ },
164
+ url: {
165
+ type: "string",
166
+ label: "File Attachment URL",
167
+ description: "URL must start with `http://` or `https://`",
168
+ },
169
+ desc: {
170
+ type: "string",
171
+ label: "Description",
172
+ description: "The description for the card",
173
+ optional: true,
174
+ },
175
+ pos: {
176
+ type: "string",
177
+ label: "Position",
178
+ description: "The position of the new card, can be `top`, `bottom`, or a positive number",
179
+ options: [
180
+ "top",
181
+ "bottom",
182
+ ],
183
+ optional: true,
184
+ },
185
+ due: {
186
+ type: "string",
187
+ label: "Due Date",
188
+ description: "Card due date in ISO format",
189
+ optional: true,
190
+ },
191
+ dueComplete: {
192
+ type: "boolean",
193
+ label: "Due Complete",
194
+ description: "Flag that indicates if `dueDate` expired",
195
+ optional: true,
196
+ },
197
+ address: {
198
+ type: "string",
199
+ label: "Address",
200
+ description: "For use with/by the Map Power-Up",
201
+ optional: true,
202
+ },
203
+ locationName: {
204
+ type: "string",
205
+ label: "Location Name",
206
+ description: "For use with/by the Map Power-Up",
207
+ optional: true,
208
+ },
209
+ coordinates: {
210
+ type: "string",
211
+ label: "Coordinates",
212
+ description: "Latitude, longitude coordinates. For use with/by the Map Power-Up. Should take the form `lat, long`.",
213
+ optional: true,
214
+ },
215
+ cardFilter: {
216
+ type: "string",
217
+ label: "Card Filter",
218
+ description: "Filter to apply to Cards. Valid values: `all`, `closed`, `none`, `open`, `visible`",
219
+ options: [
220
+ "all",
221
+ "closed",
222
+ "none",
223
+ "open",
224
+ "visible",
225
+ ],
226
+ default: "all",
227
+ },
228
+ listFilter: {
229
+ type: "string",
230
+ label: "List Filter",
231
+ description: "Type of list to search for",
232
+ options: [
233
+ "all",
234
+ "closed",
235
+ "none",
236
+ "open",
237
+ ],
238
+ default: "all",
104
239
  },
105
240
  },
106
241
  methods: {
107
- async _getBaseUrl() {
108
- return "https://api.trello.com/1"
242
+ _getBaseUrl() {
243
+ return "https://api.trello.com/1/";
109
244
  },
110
- async _getAuthorizationHeader({ data, method, url }) {
245
+ async _getAuthorizationHeader({
246
+ data, method, url,
247
+ }, $) {
111
248
  const requestData = {
112
249
  data,
113
250
  method,
@@ -117,103 +254,352 @@ module.exports = {
117
254
  key: this.$auth.oauth_access_token,
118
255
  secret: this.$auth.oauth_refresh_token,
119
256
  };
120
- return (
121
- await axios({
122
- method: "POST",
123
- url: this.$auth.oauth_signer_uri,
124
- data: {
125
- requestData,
126
- token,
127
- },
128
- })
129
- ).data;
130
- },
131
- async _makeRequest(config) {
132
- if (!config.headers) config.headers = {};
133
- const authorization = await this._getAuthorizationHeader(config);
134
- config.headers.authorization = authorization;
257
+ return axios($ ?? this, {
258
+ method: "POST",
259
+ url: this.$auth.oauth_signer_uri,
260
+ data: {
261
+ requestData,
262
+ token,
263
+ },
264
+ });
265
+ },
266
+ async _makeRequest(args, $) {
267
+ const {
268
+ method = "GET",
269
+ path,
270
+ ...otherArgs
271
+ } = args;
272
+ const config = {
273
+ method,
274
+ url: `${this._getBaseUrl()}${path}`,
275
+ ...otherArgs,
276
+ };
277
+ const authorization = await this._getAuthorizationHeader(config, $);
278
+ config.headers = {
279
+ ...config.headers,
280
+ authorization,
281
+ };
135
282
  try {
136
- return await axios(config);
283
+ return await axios($ ?? this, config);
137
284
  } catch (err) {
138
- console.log(err); // TODO
285
+ console.log(err);
139
286
  }
140
- },
141
- async verifyTrelloWebhookRequest(request, callbackURL) {
142
- let secret = this.$auth.oauth_refresh_token;
143
- var base64Digest = function (s) {
144
- return crypto.createHmac("sha1", secret).update(s).digest("base64");
287
+ },
288
+ /**
289
+ * Archives a card.
290
+ *
291
+ * @param {string} idCard - the ID of the Card to archive.
292
+ * @returns an updated card object with `closed` (archived) property set to true.
293
+ * See more at the API docs:
294
+ * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put
295
+ */
296
+ async archiveCard(idCard, $) {
297
+ const config = {
298
+ path: `cards/${idCard}`,
299
+ method: "PUT",
300
+ data: {
301
+ closed: true,
302
+ },
145
303
  };
146
- var content = JSON.stringify(request.body) + callbackURL;
147
- var doubleHash = base64Digest(content);
148
- var headerHash = request.headers["x-trello-webhook"];
149
- return doubleHash === headerHash;
304
+ return this._makeRequest(config, $);
150
305
  },
151
- async getBoard(id) {
306
+ /**
307
+ * Create an Attachment to a Card
308
+ *
309
+ * @param {string} idCard - the ID of the Card to move.
310
+ * @param {Object} params - an object containing parameters for the API request
311
+ * @returns {array} an string array with the ID of all the Card's Attachments.
312
+ * See more at the API docs:
313
+ * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-attachments-post
314
+ */
315
+ async addAttachmentToCardViaUrl(idCard, params, $) {
152
316
  const config = {
153
- url: `${await this._getBaseUrl()}/boards/${id}`,
317
+ path: `cards/${idCard}/attachments`,
318
+ method: "POST",
319
+ params,
154
320
  };
155
- return (await this._makeRequest(config)).data;
321
+ return this._makeRequest(config, $);
156
322
  },
157
- async getBoards(id) {
323
+ /**
324
+ * Adds an existing label to the specified card.
325
+ *
326
+ * @param {string} idCard - the ID of the Card to move.
327
+ * @param {Object} params - an object containing parameters for the API request
328
+ * @returns {array} an string array with the ID of all the Card's Labels.
329
+ * See more at the API docs:
330
+ * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idlabels-post
331
+ */
332
+ async addExistingLabelToCard(idCard, params, $) {
158
333
  const config = {
159
- url: `${await this._getBaseUrl()}/members/${id}/boards`,
334
+ path: `cards/${idCard}/idLabels`,
335
+ method: "POST",
336
+ params,
160
337
  };
161
- return (await this._makeRequest(config)).data;
338
+ return this._makeRequest(config, $);
162
339
  },
163
- async getCard(id) {
340
+ /**
341
+ * Add a member to a card
342
+ *
343
+ * @param {string} idCard - the ID of the Card to move.
344
+ * @param {Object} params - an object containing parameters for the API request
345
+ * @returns {array} an string array with the ID of all the Card's Members.
346
+ * See more at the API docs:
347
+ * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idmembers-post
348
+ */
349
+ async addMemberToCard(idCard, params, $) {
164
350
  const config = {
165
- url: `${await this._getBaseUrl()}/cards/${id}`,
351
+ path: `cards/${idCard}/idMembers`,
352
+ method: "POST",
353
+ params,
166
354
  };
167
- return (await this._makeRequest(config)).data;
355
+ return this._makeRequest(config, $);
168
356
  },
169
- async getCards(id) {
357
+ /**
358
+ * Creates a checklist on the specified card.
359
+ *
360
+ * @param {Object} params - an object containing parameters for the API request
361
+ * @returns an object with the created checklist.
362
+ * See more at the API docs:
363
+ * https://developer.atlassian.com/cloud/trello/rest/api-group-checklists/#api-checklists-post
364
+ */
365
+ async createChecklist(params, $) {
170
366
  const config = {
171
- url: `${await this._getBaseUrl()}/boards/${id}/cards`,
367
+ path: "checklists",
368
+ method: "POST",
369
+ params,
172
370
  };
173
- return (await this._makeRequest(config)).data;
371
+ return this._makeRequest(config, $);
174
372
  },
175
- async getChecklist(id) {
373
+ /**
374
+ * Creates a comment on a card.
375
+ *
376
+ * @param {string} idCard - the ID of the Card that the comment should be created on.
377
+ * @param {Object} params - an object containing parameters for the API request
378
+ * @returns a object containing a summary of the related card, members, and other Trello
379
+ * entities related to the newly created comment.
380
+ * See more at the API docs:
381
+ * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-actions-comments-post
382
+ */
383
+ async createCommentOnCard(idCard, comment, $) {
176
384
  const config = {
177
- url: `${await this._getBaseUrl()}/checklists/${id}`,
385
+ path: `cards/${idCard}/actions/comments`,
386
+ method: "POST",
387
+ params: {
388
+ text: comment,
389
+ },
178
390
  };
179
- return (await this._makeRequest(config)).data;
391
+ return this._makeRequest(config, $);
180
392
  },
181
- async getLabel(id) {
393
+ /**
394
+ * Closes a board.
395
+ *
396
+ * @param {string} boardId - the ID of the Board to close.
397
+ * @returns the updated board object with the `closed` property set to true.
398
+ * See more at the API docs:
399
+ * https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-put
400
+ */
401
+ async closeBoard(boardId, $) {
182
402
  const config = {
183
- url: `${await this._getBaseUrl()}/labels/${id}`,
403
+ path: `boards/${boardId}`,
404
+ method: "PUT",
405
+ data: {
406
+ closed: true,
407
+ },
184
408
  };
185
- return (await this._makeRequest(config)).data;
409
+ return this._makeRequest(config, $);
186
410
  },
187
- async getList(id) {
411
+ /**
412
+ * Creates a new card.
413
+ *
414
+ * @param {Object} opts - an object containing data for the API request
415
+ * @returns the created card object. See more at the API docs:
416
+ * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-post
417
+ */
418
+ async createCard(opts, $) {
188
419
  const config = {
189
- url: `${await this._getBaseUrl()}/lists/${id}`,
420
+ path: "cards",
421
+ method: "post",
422
+ data: opts,
190
423
  };
191
- return (await this._makeRequest(config)).data;
424
+ return this._makeRequest(config, $);
192
425
  },
193
- async getLists(id) {
426
+ /**
427
+ * Deletes the specified checklist.
428
+ *
429
+ * @param {string} idChecklist - the ID of the checklist to delete.
430
+ * @returns {object} an empty `limits` object indicating the operation completed successfully.
431
+ */
432
+ async deleteChecklist(idChecklist, $) {
194
433
  const config = {
195
- url: `${await this._getBaseUrl()}/boards/${id}/lists`,
434
+ path: `checklists/${idChecklist}`,
435
+ method: "DELETE",
196
436
  };
197
- return (await this._makeRequest(config)).data;
437
+ return this._makeRequest(config, $);
198
438
  },
199
- async getNotifications(id, params) {
439
+ /**
440
+ * Finds a label on a specific board.
441
+ *
442
+ * @param {string} boardId - unique identifier of the board to search for labels.
443
+ * @param {Object} params - an object containing parameters for the API request
444
+ * @returns {array} an array with label objects complying with the specified parameters.
445
+ */
446
+ async findLabel(boardId, params, $) {
200
447
  const config = {
201
- url: `${await this._getBaseUrl()}/members/${id}/notifications`,
448
+ path: `boards/${boardId}/labels`,
202
449
  params,
203
450
  };
204
- return (await this._makeRequest(config)).data;
451
+ return this._makeRequest(config, $);
205
452
  },
206
- async getMember(id) {
453
+ /**
454
+ * Finds a list in the specified board.
455
+ *
456
+ * @param {string} - boardId unique identifier of the board to search for lists.
457
+ * @param {Object} params - an object containing parameters for the API request
458
+ * @returns {array} an array with list objects conforming with the specified parameters.
459
+ */
460
+ async findList(boardId, params, $) {
461
+ const config = {
462
+ path: `boards/${boardId}/lists`,
463
+ params,
464
+ };
465
+ return this._makeRequest(config, $);
466
+ },
467
+ /**
468
+ * Moves a card to the specified board/list pair.
469
+ *
470
+ * @param {string} idCard the ID of the Card to move.
471
+ * @param {Object} data - an object containing data for the API request
472
+ * @returns an updated card object set to the specified board and list ids.
473
+ * See more at the API docs:
474
+ * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put
475
+ */
476
+ async moveCardToList(idCard, data, $) {
207
477
  const config = {
208
- url: `${await this._getBaseUrl()}/members/${id}`,
478
+ path: `cards/${idCard}`,
479
+ method: "PUT",
480
+ data,
209
481
  };
210
- return (await this._makeRequest(config)).data;
482
+ return this._makeRequest(config, $);
483
+ },
484
+ async verifyTrelloWebhookRequest(request, callbackURL) {
485
+ let secret = this.$auth.oauth_refresh_token;
486
+ const base64Digest = function (s) {
487
+ return crypto.createHmac("sha1", secret).update(s)
488
+ .digest("base64");
489
+ };
490
+ const content = JSON.stringify(request.body) + callbackURL;
491
+ const doubleHash = base64Digest(content);
492
+ const headerHash = request.headers["x-trello-webhook"];
493
+ return doubleHash === headerHash;
494
+ },
495
+ async getBoardActivity(boardId, filter = null) {
496
+ return this._makeRequest({
497
+ path: `boards/${boardId}/actions`,
498
+ params: {
499
+ filter,
500
+ },
501
+ });
502
+ },
503
+ async getCardActivity(cardId, filter = null) {
504
+ return this._makeRequest({
505
+ path: `cards/${cardId}/actions`,
506
+ params: {
507
+ filter,
508
+ },
509
+ });
510
+ },
511
+ async getBoard(id) {
512
+ return this._makeRequest({
513
+ path: `boards/${id}`,
514
+ });
515
+ },
516
+ async getBoards(id = this.$auth.oauth_uid) {
517
+ return this._makeRequest({
518
+ path: `members/${id}/boards`,
519
+ });
520
+ },
521
+ /**
522
+ * Gets details of a card.
523
+ *
524
+ * @param {string} id - the ID of the card to get details of.
525
+ * @returns {object} a card object. See more at the API docs:
526
+ * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-post
527
+ */
528
+ async getCard(id) {
529
+ return this._makeRequest({
530
+ path: `cards/${id}`,
531
+ });
532
+ },
533
+ async getCards(id) {
534
+ return this._makeRequest({
535
+ path: `boards/${id}/cards`,
536
+ });
537
+ },
538
+ async getFilteredCards(boardId, filter) {
539
+ return this._makeRequest({
540
+ path: `boards/${boardId}/cards`,
541
+ params: {
542
+ filter,
543
+ },
544
+ });
545
+ },
546
+ async getCardsInList(listId) {
547
+ return this._makeRequest({
548
+ path: `lists/${listId}/cards`,
549
+ });
550
+ },
551
+ async getMemberCards(userId) {
552
+ return this._makeRequest({
553
+ path: `members/${userId}/cards`,
554
+ });
555
+ },
556
+ async getChecklist(id) {
557
+ return this._makeRequest({
558
+ path: `checklists/${id}`,
559
+ });
560
+ },
561
+ async getLabel(id) {
562
+ return this._makeRequest({
563
+ path: `labels/${id}`,
564
+ });
565
+ },
566
+ async getList(id) {
567
+ return this._makeRequest({
568
+ path: `lists/${id}`,
569
+ });
570
+ },
571
+ async getLists(id) {
572
+ return this._makeRequest({
573
+ path: `boards/${id}/lists`,
574
+ });
575
+ },
576
+ async getNotifications(id, params) {
577
+ return this._makeRequest({
578
+ path: `members/${id}/notifications`,
579
+ params,
580
+ });
581
+ },
582
+ async getMember(id) {
583
+ return this._makeRequest({
584
+ path: `members/${id}`,
585
+ });
211
586
  },
212
- async createHook({ id, endpoint }) {
213
- console.log(`id: ${id}`);
587
+ async getAttachment(cardId, attachmentId) {
588
+ return this._makeRequest({
589
+ path: `cards/${cardId}/attachments/${attachmentId}`,
590
+ });
591
+ },
592
+ async getCardList(cardId) {
593
+ return this._makeRequest({
594
+ path: `cards/${cardId}/list`,
595
+ });
596
+ },
597
+ async createHook({
598
+ id, endpoint,
599
+ }) {
214
600
  const resp = await this._makeRequest({
215
601
  method: "post",
216
- url: `${await this._getBaseUrl()}/webhooks/`,
602
+ path: "webhooks/",
217
603
  headers: {
218
604
  "Content-Type": "applicaton/json",
219
605
  },
@@ -223,16 +609,132 @@ module.exports = {
223
609
  callbackURL: endpoint,
224
610
  },
225
611
  });
226
-
227
- console.log(resp);
228
-
229
- return resp.data;
612
+ return resp;
230
613
  },
231
614
  async deleteHook({ hookId }) {
232
- return await this._makeRequest({
615
+ return this._makeRequest({
233
616
  method: "delete",
234
- url: `${await this._getBaseUrl()}/webhooks/${hookId}`,
617
+ path: `webhooks/${hookId}`,
618
+ });
619
+ },
620
+ /**
621
+ * Removes an existing label from the specified card.
622
+ *
623
+ * @param {string} idCard - the ID of the Card to remove the Label from.
624
+ * @param {string} idLabel - the ID of the Label to be removed from the card.
625
+ * @returns {object} an object with the null valued property `_value` indicating that
626
+ * there were no errors
627
+ */
628
+ async removeLabelFromCard(idCard, idLabel, $) {
629
+ const config = {
630
+ path: `cards/${idCard}/idLabels/${idLabel}`,
631
+ method: "DELETE",
632
+ };
633
+ return this._makeRequest(config, $);
634
+ },
635
+ /**
636
+ * Renames the specified list
637
+ *
638
+ * @param {string} listId - the ID of the List to rename.
639
+ * @param {Object} data - an object containing data for the API request
640
+ * @returns {object} a list object with the `closed` property, indicated if the list is
641
+ * closed or archived, `id` the id of the renamed List, `idBoard` the id of the Board parent
642
+ * to the List, `name` with the new name of the List, and `pos` with the position of the List
643
+ * in the Board.
644
+ */
645
+ async renameList(listId, data, $) {
646
+ const config = {
647
+ path: `lists/${listId}`,
648
+ method: "PUT",
649
+ data,
650
+ };
651
+ return this._makeRequest(config, $);
652
+ },
653
+ /**
654
+ * Searches for members, cards, boards, and/or organizations matching the specified query.
655
+ *
656
+ * @param {Object} params - an object containing parameters for the API request
657
+ * @returns {cards: array, options: object} an array with the `cards` objects matching the
658
+ * specified `query`, and an object with the `options` for the search, such as `modelTypes` (in
659
+ * this case "cards"), `partial` the search `terms` as included in `query`, and other
660
+ * `modifiers`.
661
+ */
662
+ async search(params, $) {
663
+ const config = {
664
+ path: "search",
665
+ params,
666
+ };
667
+ return this._makeRequest(config, $);
668
+ },
669
+ /**
670
+ * Searches for boards matching the specified query.
671
+ *
672
+ * @param {Object} opts - an object containing data for the API request
673
+ * @returns {cards: array, options: object} an array with the `cards` objects matching the
674
+ * specified `query`, and an object with the `options` for the search, such as `modelTypes` (in
675
+ * this case "cards"), `partial` the search `terms` as included in `query`, and other
676
+ * `modifiers`.
677
+ */
678
+ async searchBoards(opts, $) {
679
+ const params = {
680
+ ...opts,
681
+ idOrganizations: opts.idOrganizations?.join(","),
682
+ };
683
+ return this.search(params, $);
684
+ },
685
+ /**
686
+ * Searches for cards matching the specified query.
687
+ *
688
+ * @param {Object} opts - an object containing data for the API request
689
+ * @returns {cards: array, options: object} an array with the `cards` objects matching the
690
+ * specified `query`, and an object with the `options` for the search, such as `modelTypes` (in
691
+ * this case "cards"), `partial` the search `terms` as included in `query`, and other
692
+ * `modifiers`.
693
+ */
694
+ async searchCards(opts, $) {
695
+ const params = {
696
+ ...opts,
697
+ idOrganizations: opts.idOrganizations?.join(","),
698
+ idCards: opts.idCards?.join(","),
699
+ };
700
+ return this.search(params, $);
701
+ },
702
+ /**
703
+ * Updates a card.
704
+ *
705
+ * @param {string} idCard - the ID of the card to update
706
+ * @param {Object} params - an object containing parameters for the API request
707
+ * @returns the updated card object. See more at the API docs:
708
+ * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-post
709
+ */
710
+ async updateCard(idCard,
711
+ params, $) {
712
+ const config = {
713
+ path: `cards/${idCard}`,
714
+ method: "PUT",
715
+ params,
716
+ };
717
+ return this._makeRequest(config, $);
718
+ },
719
+ async listMembers(board) {
720
+ return this._makeRequest({
721
+ path: `boards/${board}/members`,
722
+ });
723
+ },
724
+ async listBoardChecklists(board) {
725
+ return this._makeRequest({
726
+ path: `boards/${board}/checklists`,
727
+ });
728
+ },
729
+ async listCardChecklists(card) {
730
+ return this._makeRequest({
731
+ path: `cards/${card}/checklists`,
732
+ });
733
+ },
734
+ async listOrganizations(id) {
735
+ return this._makeRequest({
736
+ path: `members/${id}/organizations?fields="id,name"`,
235
737
  });
236
738
  },
237
739
  },
238
- };
740
+ };