diff --git a/components/trello/actions/add-attachment-to-card-via-url/add-attachment-to-card-via-url.mjs b/components/trello/actions/add-attachment-to-card-via-url/add-attachment-to-card-via-url.mjs deleted file mode 100644 index 06699b3d496a3..0000000000000 --- a/components/trello/actions/add-attachment-to-card-via-url/add-attachment-to-card-via-url.mjs +++ /dev/null @@ -1,73 +0,0 @@ -import common from "../common.mjs"; - -export default { - ...common, - key: "trello-add-attachment-to-card-via-url", - name: "Add Attachment to Card via URL", - description: "Adds a file attachment on a card by referencing a public URL. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-attachments-post)", - version: "0.0.3", - type: "action", - props: { - ...common.props, - board: { - propDefinition: [ - common.props.trello, - "board", - ], - }, - idCard: { - propDefinition: [ - common.props.trello, - "cards", - (c) => ({ - board: c.board, - }), - ], - type: "string", - label: "Card", - description: "The ID of the Card to add the Attachment to", - optional: false, - }, - name: { - propDefinition: [ - common.props.trello, - "name", - ], - }, - url: { - propDefinition: [ - common.props.trello, - "url", - ], - }, - mimeType: { - propDefinition: [ - common.props.trello, - "mimeType", - ], - }, - setCover: { - type: "boolean", - label: "Set Cover?", - description: "Determines whether to use the new attachment as a cover for the Card", - default: false, - }, - }, - async run({ $ }) { - const { - idCard, - name, - url, - mimeType, - setCover, - } = this; - const res = await this.trello.addAttachmentToCardViaUrl(idCard, { - name, - url, - mimeType, - setCover, - }, $); - $.export("$summary", `Successfully added attachement to card ${idCard}`); - return res; - }, -}; diff --git a/components/trello/actions/add-attachment-to-card/add-attachment-to-card.mjs b/components/trello/actions/add-attachment-to-card/add-attachment-to-card.mjs new file mode 100644 index 0000000000000..7f401f3bfcb5f --- /dev/null +++ b/components/trello/actions/add-attachment-to-card/add-attachment-to-card.mjs @@ -0,0 +1,124 @@ +import { ConfigurationError } from "@pipedream/platform"; +import fs from "fs"; +import FormData from "form-data"; +import common from "../common.mjs"; + +export default { + ...common, + key: "trello-add-attachment-to-card", + name: "Add Attachment To Card", + description: "Adds a file attachment on a card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-attachments-post)", + version: "0.0.1", + type: "action", + props: { + ...common.props, + board: { + propDefinition: [ + common.props.app, + "board", + ], + }, + cardId: { + propDefinition: [ + common.props.app, + "cards", + (c) => ({ + board: c.board, + }), + ], + type: "string", + label: "Card", + description: "The ID of the Card to add the Attachment to", + optional: false, + }, + name: { + propDefinition: [ + common.props.app, + "name", + ], + }, + url: { + propDefinition: [ + common.props.app, + "url", + ], + }, + mimeType: { + propDefinition: [ + common.props.app, + "mimeType", + ], + }, + file: { + propDefinition: [ + common.props.app, + "file", + ], + }, + setCover: { + type: "boolean", + label: "Set Cover?", + description: "Determines whether to use the new attachment as a cover for the Card", + default: false, + }, + }, + methods: { + ...common.methods, + addAttachmentToCard({ + cardId, ...args + } = {}) { + return this.app.post({ + path: `/cards/${cardId}/attachments`, + ...args, + }); + }, + }, + async run({ $ }) { + const { + addAttachmentToCard, + cardId, + name, + url, + mimeType, + setCover, + file, + } = this; + + let response; + const params = { + name, + mimeType, + setCover, + }; + + if (file && !file?.startsWith("/tmp")) { + throw new ConfigurationError("The file path must be in the `/tmp` directory"); + } + + if (file) { + const form = new FormData(); + form.append("file", fs.createReadStream(file)); + + response = await addAttachmentToCard({ + $, + cardId, + params, + headers: form.getHeaders(), + data: form, + }); + + } else { + response = await addAttachmentToCard({ + $, + cardId, + params: { + ...params, + url, + }, + }); + } + + $.export("$summary", `Successfully added attachement to card ${cardId}`); + return response; + }, +}; diff --git a/components/trello/actions/add-checklist/add-checklist.mjs b/components/trello/actions/add-checklist/add-checklist.mjs index e41ec3040df6e..b47af479b96fa 100644 --- a/components/trello/actions/add-checklist/add-checklist.mjs +++ b/components/trello/actions/add-checklist/add-checklist.mjs @@ -1,68 +1,86 @@ -// legacy_hash_id: a_WYieM3 -import { axios } from "@pipedream/platform"; +import app from "../../trello.app.mjs"; export default { key: "trello-add-checklist", name: "Create a Checklist", - description: "Adds a new checklist to a card.", - version: "0.1.3", + description: "Adds a new checklist to a card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-checklists-post).", + version: "0.2.0", type: "action", props: { - trello: { - type: "app", - app: "trello", + app, + boardId: { + propDefinition: [ + app, + "board", + ], }, - id: { + cardId: { type: "string", + label: "Card ID", description: "The ID of the card.", + optional: false, + propDefinition: [ + app, + "cards", + ({ boardId }) => ({ + board: boardId, + }), + ], }, name: { type: "string", + label: "Checklist Name", description: "The name of the checklist.", optional: true, }, idChecklistSource: { - type: "string", - description: "The ID of a source checklist to copy into the new one.", optional: true, + propDefinition: [ + app, + "checklist", + ({ boardId }) => ({ + board: boardId, + }), + ], }, pos: { type: "string", + label: "Position", description: "The position of the checklist on the card. One of: top, bottom, or a positive number.", optional: true, }, }, + methods: { + addChecklist({ + cardId, ...args + } = {}) { + return this.app.post({ + path: `/cards/${cardId}/checklists`, + ...args, + }); + }, + }, async run({ $ }) { - const oauthSignerUri = this.trello.$auth.oauth_signer_uri; - - let id = this.id; - const trelloParams = [ - "name", - "idChecklistSource", - "pos", - ]; - let p = this; - - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`) - .join("&"); - - const config = { - url: `https://api.trello.com/1/cards/${id}/checklists?${queryString}`, - method: "POST", - data: "", - }; + const { + addChecklist, + cardId, + name, + idChecklistSource, + pos, + } = this; - const token = { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }; + const response = await addChecklist({ + $, + cardId, + params: { + name, + idChecklistSource, + pos, + }, + }); - const signConfig = { - token, - oauthSignerUri, - }; + $.export("$summary", "Successfully added checklist."); - const resp = await axios($, config, signConfig); - return resp; + return response; }, }; diff --git a/components/trello/actions/add-comment/add-comment.mjs b/components/trello/actions/add-comment/add-comment.mjs index 17c1e4e76697a..96c8a7f605556 100644 --- a/components/trello/actions/add-comment/add-comment.mjs +++ b/components/trello/actions/add-comment/add-comment.mjs @@ -1,55 +1,65 @@ -// legacy_hash_id: a_Xzi26w -import { axios } from "@pipedream/platform"; +import app from "../../trello.app.mjs"; export default { key: "trello-add-comment", name: "Create a Comment", - description: "Create a new comment on a specific card.", - version: "0.1.3", + description: "Create a new comment on a specific card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-actions-comments-post).", + version: "0.2.0", type: "action", props: { - trello: { - type: "app", - app: "trello", + app, + boardId: { + propDefinition: [ + app, + "board", + ], }, - id: { + cardId: { type: "string", + label: "Card ID", description: "The ID of the card.", + optional: false, + propDefinition: [ + app, + "cards", + ({ boardId }) => ({ + board: boardId, + }), + ], }, text: { type: "string", + label: "Comment", description: "The comment to add.", }, }, + methods: { + addComment({ + cardId, ...args + } = {}) { + return this.app.post({ + path: `/cards/${cardId}/actions/comments`, + ...args, + }); + }, + }, async run({ $ }) { - const oauthSignerUri = this.trello.$auth.oauth_signer_uri; - - let id = this.id; - const trelloParams = [ - "text", - ]; - let p = this; - - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`) - .join("&"); - - const config = { - url: `https://api.trello.com/1/cards/${id}/actions/comments?${queryString}`, - method: "POST", - data: "", - }; + const { + addComment, + cardId, + text, + } = this; - const token = { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }; + const response = await addComment({ + $, + cardId, + params: { + text, + }, + }); - const signConfig = { - token, - oauthSignerUri, - }; + $.export("$summary", "Successfully added comment."); - const resp = await axios($, config, signConfig); - return resp; + return response; }, }; diff --git a/components/trello/actions/add-existing-label-to-card/add-existing-label-to-card.mjs b/components/trello/actions/add-existing-label-to-card/add-existing-label-to-card.mjs index bd364f17cb99e..1c47f5c09ea91 100644 --- a/components/trello/actions/add-existing-label-to-card/add-existing-label-to-card.mjs +++ b/components/trello/actions/add-existing-label-to-card/add-existing-label-to-card.mjs @@ -4,20 +4,20 @@ export default { ...common, key: "trello-add-existing-label-to-card", name: "Add Existing Label to Card", - description: "Adds an existing label to the specified card. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idlabels-post)", - version: "0.0.3", + description: "Adds an existing label to the specified card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idlabels-post).", + version: "0.1.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, - idCard: { + cardId: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -28,9 +28,9 @@ export default { description: "The ID of the Card to add the Label to", optional: false, }, - idLabel: { + value: { propDefinition: [ - common.props.trello, + common.props.app, "label", (c) => ({ board: c.board, @@ -38,11 +38,26 @@ export default { ], }, }, + methods: { + ...common.methods, + addExistingLabelToCard({ + cardId, ...args + } = {}) { + return this.app.post({ + path: `/cards/${cardId}/idLabels`, + ...args, + }); + }, + }, async run({ $ }) { - const res = await this.trello.addExistingLabelToCard(this.idCard, { - value: this.idLabel, - }, $); - $.export("$summary", `Successfully added label ${this.idLabel} to card ${this.idCard}`); + const res = await this.addExistingLabelToCard({ + $, + cardId: this.cardId, + params: { + value: this.value, + }, + }); + $.export("$summary", `Successfully added label and returned \`${res.length}\` labels added.`); return res; }, }; diff --git a/components/trello/actions/add-file-as-attachment-via-url/add-file-as-attachment-via-url.mjs b/components/trello/actions/add-file-as-attachment-via-url/add-file-as-attachment-via-url.mjs deleted file mode 100644 index 2be40f372389e..0000000000000 --- a/components/trello/actions/add-file-as-attachment-via-url/add-file-as-attachment-via-url.mjs +++ /dev/null @@ -1,72 +0,0 @@ -// legacy_hash_id: a_elirYr -import { axios } from "@pipedream/platform"; - -export default { - key: "trello-add-file-as-attachment-via-url", - name: "Add Attachment to Card via URL", - description: "Create a file attachment on a card by referencing a public URL", - version: "0.1.3", - type: "action", - props: { - trello: { - type: "app", - app: "trello", - }, - name: { - type: "string", - label: "Name", - description: "The name of the attachment. Max length 256.", - optional: true, - }, - mimeType: { - type: "string", - label: "MIME Type", - description: "The mimeType of the attachment. Max length 256.", - optional: true, - }, - url: { - type: "string", - label: "File URL", - description: "A URL to a file you'd like to attach. Must start with http:// or https://", - }, - id: { - type: "string", - label: "ID", - description: "The ID of your Trello card", - }, - }, - async run({ $ }) { - const oauthSignerUri = this.trello.$auth.oauth_signer_uri; - - const trelloParams = [ - "name", - "mimeType", - "url", - ]; - let p = this; - - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${encodeURIComponent(p[param])}`) - .join("&"); - - const config = { - url: `https://api.trello.com/1/cards/${this.id}/attachments?${queryString}`, - method: "POST", - headers: { - "Content-Type": "application/json", - }, - }; - - const token = { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }; - - const signConfig = { - token, - oauthSignerUri, - }; - - const resp = await axios($, config, signConfig); - return resp; - }, -}; diff --git a/components/trello/actions/add-image-attachment/add-image-attachment.mjs b/components/trello/actions/add-image-attachment/add-image-attachment.mjs deleted file mode 100644 index a8783c1d69dea..0000000000000 --- a/components/trello/actions/add-image-attachment/add-image-attachment.mjs +++ /dev/null @@ -1,75 +0,0 @@ -// legacy_hash_id: a_B0im8k -import { axios } from "@pipedream/platform"; - -export default { - key: "trello-add-image-attachment", - name: "Add Image Attachment to Card", - description: "Adds image to card", - version: "0.1.4", - type: "action", - props: { - trello: { - type: "app", - app: "trello", - }, - id: { - type: "string", - description: "The ID of the card.", - }, - name: { - type: "string", - description: "The name of the attachment. Max length 256.", - optional: true, - }, - file: { - type: "string", - description: "The file to attach, as multipart/form-data", - optional: true, - }, - mimeType: { - type: "string", - description: "The mimeType of the attachment. Max length 256.", - optional: true, - }, - url: { - type: "string", - description: "A URL to attach. Must start with http:// or https://", - }, - }, - async run({ $ }) { - const oauthSignerUri = this.trello.$auth.oauth_signer_uri; - - let id = this.id; - const trelloParams = [ - "name", - "file", - "mimeType", - "url", - ]; - let p = this; - - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`) - .join("&"); - - const config = { - url: `https://api.trello.com/1/cards/${id}/attachments?${queryString}`, - method: "POST", - headers: { - "Content-Type": "application/json", - }, - }; - - const token = { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }; - - const signConfig = { - token, - oauthSignerUri, - }; - - const resp = await axios($, config, signConfig); - return resp; - }, -}; diff --git a/components/trello/actions/add-label-to-card/add-label-to-card.mjs b/components/trello/actions/add-label-to-card/add-label-to-card.mjs deleted file mode 100644 index d15ebcec63137..0000000000000 --- a/components/trello/actions/add-label-to-card/add-label-to-card.mjs +++ /dev/null @@ -1,55 +0,0 @@ -// legacy_hash_id: a_xqi4E7 -import { axios } from "@pipedream/platform"; - -export default { - key: "trello-add-label-to-card", - name: "Add Existing Label to Card", - description: "Add an existing label to a card.", - version: "0.1.3", - type: "action", - props: { - trello: { - type: "app", - app: "trello", - }, - id: { - type: "string", - description: "The ID of the card.", - }, - value: { - type: "string", - description: "The ID of the label to add", - }, - }, - async run({ $ }) { - const oauthSignerUri = this.trello.$auth.oauth_signer_uri; - - let id = this.id; - const trelloParams = [ - "value", - ]; - let p = this; - - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`) - .join("&"); - - const config = { - url: `https://api.trello.com/1/cards/${id}/idLabels?${queryString}`, - method: "POST", - data: "", - }; - - const token = { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }; - - const signConfig = { - token, - oauthSignerUri, - }; - - const resp = await axios($, config, signConfig); - return resp; - }, -}; diff --git a/components/trello/actions/add-member-to-card/add-member-to-card.mjs b/components/trello/actions/add-member-to-card/add-member-to-card.mjs index b16c38df87007..ff66c3e6b6bb8 100644 --- a/components/trello/actions/add-member-to-card/add-member-to-card.mjs +++ b/components/trello/actions/add-member-to-card/add-member-to-card.mjs @@ -4,20 +4,20 @@ export default { ...common, key: "trello-add-member-to-card", name: "Add Member to Card", - description: "Adds a member to the specified card. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idmembers-post)", - version: "0.1.4", + description: "Adds a member to the specified card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idmembers-post).", + version: "0.2.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, - idCard: { + cardId: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -28,9 +28,9 @@ export default { description: "The ID of the Card to add the Member to", optional: false, }, - idMember: { + value: { propDefinition: [ - common.props.trello, + common.props.app, "member", (c) => ({ board: c.board, @@ -38,11 +38,26 @@ export default { ], }, }, + methods: { + ...common.methods, + addMemberToCard({ + cardId, ...args + } = {}) { + return this.app.post({ + path: `/cards/${cardId}/idMembers`, + ...args, + }); + }, + }, async run({ $ }) { - const res = await this.trello.addMemberToCard(this.idCard, { - value: this.idMember, - }, $); - $.export("$summary", `Successfully added member ${res[0].fullName} to card ${this.idCard}`); + const res = await this.addMemberToCard({ + $, + cardId: this.cardId, + params: { + value: this.value, + }, + }); + $.export("$summary", `Successfully added member ${res[0].fullName} to card ${this.cardId}`); return res; }, }; diff --git a/components/trello/actions/archive-card/archive-card.mjs b/components/trello/actions/archive-card/archive-card.mjs index ca61ade8ce47e..0e15e0369c5a7 100644 --- a/components/trello/actions/archive-card/archive-card.mjs +++ b/components/trello/actions/archive-card/archive-card.mjs @@ -4,20 +4,20 @@ export default { ...common, key: "trello-archive-card", name: "Archive Card", - description: "Archives a card. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put)", - version: "0.1.4", + description: "Archives a card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put).", + version: "0.2.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, - idCard: { + cardId: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -30,8 +30,14 @@ export default { }, }, async run({ $ }) { - const res = await this.trello.archiveCard(this.idCard, $); - $.export("$summary", `Successfully archived card ${this.idCard}`); + const res = await this.app.updateCard({ + $, + cardId: this.cardId, + data: { + closed: true, + }, + }); + $.export("$summary", `Successfully archived card ${this.cardId}`); return res; }, }; diff --git a/components/trello/actions/close-board/close-board.mjs b/components/trello/actions/close-board/close-board.mjs index 33d4e42b6769e..f286947b9992f 100644 --- a/components/trello/actions/close-board/close-board.mjs +++ b/components/trello/actions/close-board/close-board.mjs @@ -4,21 +4,27 @@ export default { ...common, key: "trello-close-board", name: "Close Board", - description: "Closes a board. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-put)", - version: "0.0.3", + description: "Closes a board. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-put).", + version: "0.1.0", type: "action", props: { ...common.props, boardId: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], description: "The ID of the Board to close", }, }, async run({ $ }) { - const res = await this.trello.closeBoard(this.boardId, $); + const res = await this.app.updateBoard({ + $, + boardId: this.boardId, + data: { + closed: true, + }, + }); $.export("$summary", `Successfully closed board ${this.boardId}`); return res; }, diff --git a/components/trello/actions/common.mjs b/components/trello/actions/common.mjs index e7c49e7c56099..6e32f78c5ebf1 100644 --- a/components/trello/actions/common.mjs +++ b/components/trello/actions/common.mjs @@ -1,8 +1,8 @@ -import trello from "../trello.app.mjs"; +import app from "../trello.app.mjs"; export default { props: { - trello, + app, }, methods: { /** diff --git a/components/trello/actions/complete-checklist-item/complete-checklist-item.mjs b/components/trello/actions/complete-checklist-item/complete-checklist-item.mjs index 4dea355af3e41..4ee9cd982a226 100644 --- a/components/trello/actions/complete-checklist-item/complete-checklist-item.mjs +++ b/components/trello/actions/complete-checklist-item/complete-checklist-item.mjs @@ -1,49 +1,79 @@ -// legacy_hash_id: a_EViowW -import { axios } from "@pipedream/platform"; +import app from "../../trello.app.mjs"; export default { key: "trello-complete-checklist-item", name: "Complete a Checklist Item", - description: "Completes an existing checklist item in a card.", - version: "0.1.3", + description: "Completes an existing checklist item in a card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-checkitem-idcheckitem-put).", + version: "0.2.0", type: "action", props: { - trello: { - type: "app", - app: "trello", + app, + board: { + propDefinition: [ + app, + "board", + ], }, - id: { + cardId: { + propDefinition: [ + app, + "cards", + (c) => ({ + board: c.board, + }), + ], type: "string", + label: "Card ID", description: "The ID of the card.", + optional: false, }, - idCheckItem: { - type: "string", - description: "The ID of the checklist item to complete.", + checklistId: { + propDefinition: [ + app, + "checklist", + ({ cardId }) => ({ + card: cardId, + }), + ], + }, + checklistItemId: { + propDefinition: [ + app, + "checklistItemId", + ({ checklistId }) => ({ + checklistId, + }), + ], + }, + }, + methods: { + completeChecklistItem({ + cardId, checklistItemId, ...args + } = {}) { + return this.app.put({ + path: `/cards/${cardId}/checkItem/${checklistItemId}`, + ...args, + }); }, }, async run({ $ }) { - const oauthSignerUri = this.trello.$auth.oauth_signer_uri; - - let id = this.id; - let idCheckItem = this.idCheckItem; - - const config = { - url: `https://api.trello.com/1/cards/${id}/checkItem/${idCheckItem}?state=complete`, - method: "PUT", - data: "", - }; + const { + completeChecklistItem, + cardId, + checklistItemId, + } = this; - const token = { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }; + const response = await completeChecklistItem({ + $, + cardId, + checklistItemId, + params: { + state: "complete", + }, + }); - const signConfig = { - token, - oauthSignerUri, - }; + $.export("$summary", "Successfully completed checklist item."); - const resp = await axios($, config, signConfig); - return resp; + return response; }, }; diff --git a/components/trello/actions/copy-board/copy-board.mjs b/components/trello/actions/copy-board/copy-board.mjs deleted file mode 100644 index d5c37d5c2fdab..0000000000000 --- a/components/trello/actions/copy-board/copy-board.mjs +++ /dev/null @@ -1,174 +0,0 @@ -// legacy_hash_id: a_B0izQg -import { axios } from "@pipedream/platform"; - -export default { - key: "trello-copy-board", - name: "Copy a Board", - description: "Creates a copy of an existing board.", - version: "0.1.3", - type: "action", - props: { - trello: { - type: "app", - app: "trello", - }, - name: { - type: "string", - description: "The new name for the board. 1 to 16384 characters long.", - }, - defaultLabels: { - type: "boolean", - description: "Determines whether to use the default set of labels.", - optional: true, - }, - defaultLists: { - type: "boolean", - description: "Determines whether to add the default set of lists to a board (To Do, Doing, Done). It is ignored if idBoardSource is provided.", - optional: true, - }, - desc: { - type: "string", - description: "A new description for the board, 0 to 16384 characters long.", - optional: true, - }, - idOrganization: { - type: "string", - description: "The id or name of the team the board should belong to.", - optional: true, - }, - idBoardSource: { - type: "string", - description: "The id of a board to copy into the new board.", - }, - keepFromSource: { - type: "string", - description: "To keep cards from the original board pass in the value \"cards\".", - optional: true, - options: [ - "none", - "cards", - ], - }, - powerUps: { - type: "string", - description: "The Power-Ups that should be enabled on the new board. One of: all, calendar, cardAging, recap, voting.", - optional: true, - }, - prefs_permissionLevel: { - type: "string", - description: "The permissions level of the board. One of: org, private, public.", - optional: true, - options: [ - "org", - "private", - "public", - ], - }, - prefs_voting: { - type: "string", - label: "Prefs Voting", - description: "Who can vote on this board. One of disabled, members, observers, org, public.", - optional: true, - options: [ - "disabled", - "members", - "observers", - "org", - "public", - ], - }, - prefs_comments: { - type: "string", - label: "Prefs Comments", - description: "Who can comment on cards on this board. One of: disabled, members, observers, org, public.", - optional: true, - options: [ - "disabled", - "members", - "observers", - "org", - "public", - ], - }, - prefs_invitations: { - type: "string", - label: "Prefs Invitations", - description: "Determines what types of members can invite users to join. One of: admins, members.", - optional: true, - options: [ - "admins", - "members", - ], - }, - prefs_selfJoin: { - type: "boolean", - description: "Determines whether users can join the boards themselves or whether they have to be invited.", - optional: true, - }, - prefs_cardCovers: { - type: "string", - description: "Determines whether card covers are enabled.", - optional: true, - }, - prefs_background: { - type: "string", - label: "Prefs Background", - description: "The id of a custom background or one of: blue, orange, green, red, purple, pink, lime, sky, grey.", - optional: true, - }, - prefs_cardAging: { - type: "string", - description: "Determines the type of card aging that should take place on the board if card aging is enabled. One of: pirate, regular.", - optional: true, - options: [ - "pirate", - "regular", - ], - }, - }, - async run({ $ }) { - const oauthSignerUri = this.trello.$auth.oauth_signer_uri; - - const trelloParams = [ - "name", - "defaultLabels", - "defaultLists", - "desc", - "idOrganization", - "idBoardSource", - "keepFromSource", - "powerUps", - "prefs_permissionLevel", - "prefs_voting", - "prefs_comments", - "prefs_invitations", - "prefs_selfJoin", - "prefs_cardCovers", - "prefs_background", - "prefs_cardAging", - ]; - let p = this; - - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`) - .join("&"); - - const config = { - url: `https://api.trello.com/1/boards?${queryString}`, - method: "POST", - data: "", - }; - - const token = { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }; - - const signConfig = { - token, - oauthSignerUri, - }; - - const resp = await axios($, config, signConfig); - return resp; - }, -}; diff --git a/components/trello/actions/create-board/create-board.mjs b/components/trello/actions/create-board/create-board.mjs index 451c310ce18a1..714ecca952b11 100644 --- a/components/trello/actions/create-board/create-board.mjs +++ b/components/trello/actions/create-board/create-board.mjs @@ -1,49 +1,59 @@ -// legacy_hash_id: a_Nqi0GV -import { axios } from "@pipedream/platform"; +import app from "../../trello.app.mjs"; export default { key: "trello-create-board", name: "Create a Board", - description: "Creates a new Trello board.", - version: "0.1.3", + description: "Creates a new Trello board. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-post).", + version: "0.2.0", type: "action", props: { - trello: { - type: "app", - app: "trello", - }, + app, name: { type: "string", + label: "Name", description: "The new name for the board. 1 to 16384 characters long.", }, defaultLabels: { type: "boolean", + label: "Default Labels", description: "Determines whether to use the default set of labels.", optional: true, }, defaultLists: { type: "boolean", + label: "Default Lists", description: "Determines whether to add the default set of lists to a board (To Do, Doing, Done). It is ignored if idBoardSource is provided.", optional: true, }, desc: { type: "string", + label: "Description", description: "A new description for the board, 0 to 16384 characters long", optional: true, }, idOrganization: { type: "string", + label: "Organization ID", description: "The id or name of the team the board should belong to.", - optional: true, + optional: false, + propDefinition: [ + app, + "idOrganizations", + ], }, idBoardSource: { - type: "string", + label: "Board Source ID", description: "The id of a board to copy into the new board.", optional: true, + propDefinition: [ + app, + "board", + ], }, keepFromSource: { type: "string", - description: "To keep cards from the original board pass in the value \"cards\".", + label: "Keep From Source", + description: "To keep cards from the original board pass in the value `cards`.", optional: true, options: [ "none", @@ -52,12 +62,21 @@ export default { }, powerUps: { type: "string", - description: "The Power-Ups that should be enabled on the new board. One of: all, calendar, cardAging, recap, voting.", + label: "Power-Ups", + description: "The Power-Ups that should be enabled on the new board. One of: `all`, `calendar`, `cardAging`, `recap`, `voting`.", optional: true, + options: [ + "all", + "calendar", + "cardAging", + "recap", + "voting", + ], }, - prefs_permissionLevel: { + prefsPermissionLevel: { type: "string", description: "The permissions level of the board. One of: org, private, public.", + label: "Prefs Permission Level", optional: true, options: [ "org", @@ -65,7 +84,7 @@ export default { "public", ], }, - prefs_voting: { + prefsVoting: { type: "string", label: "Prefs Voting", description: "Who can vote on this board. One of disabled, members, observers, org, public.", @@ -78,7 +97,7 @@ export default { "public", ], }, - prefs_comments: { + prefsComments: { type: "string", label: "Prefs Comments", description: "Who can comment on cards on this board. One of: disabled, members, observers, org, public.", @@ -91,7 +110,7 @@ export default { "public", ], }, - prefs_invitations: { + prefsInvitations: { type: "string", label: "Prefs Invitations", description: "Determines what types of members can invite users to join. One of: admins, members.", @@ -101,24 +120,38 @@ export default { "members", ], }, - prefs_selfJoin: { + prefsSelfJoin: { type: "boolean", + label: "Prefs Self Join", description: "Determines whether users can join the boards themselves or whether they have to be invited.", optional: true, }, - prefs_cardCovers: { + prefsCardCovers: { type: "boolean", + label: "Prefs Card Covers", description: "Determines whether card covers are enabled.", optional: true, }, - prefs_background: { + prefsBackground: { type: "string", label: "Prefs Background", - description: "The id of a custom background or one of: blue, orange, green, red, purple, pink, lime, sky, grey.", + description: "The id of a custom background or one of: `blue`, `orange`, `green`, `red`, `purple`, `pink`, `lime`, `sky`, `grey`.", optional: true, + options: [ + "blue", + "orange", + "green", + "red", + "purple", + "pink", + "lime", + "sky", + "grey", + ], }, - prefs_cardAging: { + prefsCardAging: { type: "string", + label: "Prefs Card Aging", description: "Determines the type of card aging that should take place on the board if card aging is enabled. One of: pirate, regular.", optional: true, options: [ @@ -128,48 +161,50 @@ export default { }, }, async run({ $ }) { - const oauthSignerUri = this.trello.$auth.oauth_signer_uri; - - const trelloParams = [ - "name", - "defaultLabels", - "defaultLists", - "desc", - "idOrganization", - "idBoardSource", - "keepFromSource", - "powerUps", - "prefs_permissionLevel", - "prefs_voting", - "prefs_comments", - "prefs_invitations", - "prefs_selfJoin", - "prefs_cardCovers", - "prefs_background", - "prefs_cardAging", - ]; - let p = this; - - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`) - .join("&"); - - const config = { - url: `https://api.trello.com/1/boards?${queryString}`, - method: "POST", - data: "", - }; + const { + app, + name, + defaultLabels, + defaultLists, + desc, + idOrganization, + idBoardSource, + keepFromSource, + powerUps, + prefsPermissionLevel, + prefsVoting, + prefsComments, + prefsInvitations, + prefsSelfJoin, + prefsCardCovers, + prefsBackground, + prefsCardAging, + } = this; - const token = { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }; + const response = await app.createBoard({ + $, + params: { + name, + defaultLabels, + defaultLists, + desc, + idOrganization, + idBoardSource, + keepFromSource, + powerUps, + prefs_permissionLevel: prefsPermissionLevel, + prefs_voting: prefsVoting, + prefs_comments: prefsComments, + prefs_invitations: prefsInvitations, + prefs_selfJoin: prefsSelfJoin, + prefs_cardCovers: prefsCardCovers, + prefs_background: prefsBackground, + prefs_cardAging: prefsCardAging, + }, + }); - const signConfig = { - token, - oauthSignerUri, - }; + $.export("$summary", `Successfully created board with ID \`${response.id}\`.`); - const resp = await axios($, config, signConfig); - return resp; + return response; }, }; diff --git a/components/trello/actions/create-card/create-card.mjs b/components/trello/actions/create-card/create-card.mjs index 2899b67e8bfc9..b073448ee8c56 100644 --- a/components/trello/actions/create-card/create-card.mjs +++ b/components/trello/actions/create-card/create-card.mjs @@ -1,23 +1,26 @@ +import fs from "fs"; +import FormData from "form-data"; +import { ConfigurationError } from "@pipedream/platform"; import common from "../common.mjs"; export default { ...common, key: "trello-create-card", name: "Create Card", - description: "Creates a new card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-post)", - version: "0.0.3", + description: "Creates a new card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-post).", + version: "0.1.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, name: { propDefinition: [ - common.props.trello, + common.props.app, "name", ], description: "The name of the card.", @@ -25,31 +28,31 @@ export default { }, desc: { propDefinition: [ - common.props.trello, + common.props.app, "desc", ], }, pos: { propDefinition: [ - common.props.trello, + common.props.app, "pos", ], }, due: { propDefinition: [ - common.props.trello, + common.props.app, "due", ], }, dueComplete: { propDefinition: [ - common.props.trello, + common.props.app, "dueComplete", ], }, idList: { propDefinition: [ - common.props.trello, + common.props.app, "lists", (c) => ({ board: c.board, @@ -62,7 +65,7 @@ export default { }, idMembers: { propDefinition: [ - common.props.trello, + common.props.app, "member", (c) => ({ board: c.board, @@ -75,7 +78,7 @@ export default { }, idLabels: { propDefinition: [ - common.props.trello, + common.props.app, "label", (c) => ({ board: c.board, @@ -88,26 +91,25 @@ export default { }, urlSource: { propDefinition: [ - common.props.trello, + common.props.app, "url", ], - optional: true, - }, - fileSource: { - type: "string", - label: "File Attachment Contents", - description: "Value must be in binary format", - optional: true, }, mimeType: { propDefinition: [ - common.props.trello, + common.props.app, "mimeType", ], }, + file: { + propDefinition: [ + common.props.app, + "file", + ], + }, idCardSource: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -115,7 +117,7 @@ export default { ], type: "string", label: "Copy Card", - description: "Specify an existing card to copy contents from", + description: "Specify an existing card to copy contents from. Keep in mind that if you copy a card, the **File Attachment Path**, **File Attachment URL** and **File Attachment Type** fields will be ignored.", }, keepFromSource: { type: "string[]", @@ -135,25 +137,25 @@ export default { }, address: { propDefinition: [ - common.props.trello, + common.props.app, "address", ], }, locationName: { propDefinition: [ - common.props.trello, + common.props.app, "locationName", ], }, coordinates: { propDefinition: [ - common.props.trello, + common.props.app, "coordinates", ], }, customFieldIds: { propDefinition: [ - common.props.trello, + common.props.app, "customFieldIds", (c) => ({ boardId: c.board, @@ -168,7 +170,9 @@ export default { return props; } for (const customFieldId of this.customFieldIds) { - const customField = await this.trello.getCustomField(customFieldId); + const customField = await this.app.getCustomField({ + customFieldId, + }); props[customFieldId] = { type: "string", label: `Value for Custom Field - ${customField.name}`, @@ -187,7 +191,10 @@ export default { async getCustomFieldItems($) { const customFieldItems = []; for (const customFieldId of this.customFieldIds) { - const customField = await this.trello.getCustomField(customFieldId, $); + const customField = await this.app.getCustomField({ + $, + customFieldId, + }); const customFieldItem = { idCustomField: customFieldId, }; @@ -206,9 +213,16 @@ export default { } return customFieldItems; }, + createCard(args = {}) { + return this.app.post({ + path: "/cards", + ...args, + }); + }, }, async run({ $ }) { const { + createCard, name, desc, pos, @@ -218,8 +232,8 @@ export default { idMembers, idLabels, urlSource, - fileSource, mimeType, + file, idCardSource, keepFromSource, address, @@ -227,7 +241,9 @@ export default { coordinates, customFieldIds, } = this; - const res = await this.trello.createCard({ + + let response; + const params = { name, desc, pos, @@ -236,25 +252,53 @@ export default { idList, idMembers, idLabels, - urlSource, - fileSource, mimeType, idCardSource, keepFromSource: keepFromSource?.join(","), address, locationName, coordinates, - }, $); + }; + + if (file && !file?.startsWith("/tmp")) { + throw new ConfigurationError("The file path must be in the `/tmp` directory"); + } + + if (file) { + const form = new FormData(); + form.append("fileSource", fs.createReadStream(file)); + + response = await createCard({ + $, + params, + headers: form.getHeaders(), + data: form, + }); + + } else { + response = await createCard({ + $, + params: { + ...params, + urlSource, + }, + }); + } if (customFieldIds) { const customFieldItems = await this.getCustomFieldItems($); - const customFields = await this.trello.updateCustomFields(res.id, { - customFieldItems, - }, $); - res.customFields = customFields; + const customFields = await this.app.updateCustomFields({ + $, + cardId: response.id, + data: { + customFieldItems, + }, + }); + response.customFields = customFields; } - $.export("$summary", `Successfully created card ${res.id}`); - return res; + $.export("$summary", `Successfully created card \`${response.id}\`.`); + + return response; }, }; diff --git a/components/trello/actions/create-checklist-item/create-checklist-item.mjs b/components/trello/actions/create-checklist-item/create-checklist-item.mjs index 33f59bd7fe5d2..2615ed122af50 100644 --- a/components/trello/actions/create-checklist-item/create-checklist-item.mjs +++ b/components/trello/actions/create-checklist-item/create-checklist-item.mjs @@ -1,67 +1,92 @@ -// legacy_hash_id: a_bKiP4j -import { axios } from "@pipedream/platform"; +import app from "../../trello.app.mjs"; export default { key: "trello-create-checklist-item", name: "Create a Checklist Item", - description: "Creates a new checklist item in a card.", - version: "0.1.3", + description: "Creates a new checklist item in a card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-checklists/#api-checklists-id-checkitems-post).", + version: "0.2.0", type: "action", props: { - trello: { - type: "app", - app: "trello", + app, + board: { + propDefinition: [ + app, + "board", + ], }, - id: { + card: { + propDefinition: [ + app, + "cards", + ({ board }) => ({ + board, + }), + ], type: "string", + label: "Card", + description: "The ID of the Card that the checklist item should be added to", + optional: false, + }, + checklistId: { + label: "Checklist ID", description: "ID of a checklist.", + propDefinition: [ + app, + "checklist", + ({ card }) => ({ + card, + }), + ], }, name: { type: "string", + label: "Name", description: "The name of the new check item on the checklist. Should be a string of length 1 to 16384.", }, pos: { - type: "string", - description: "The position of the check item in the checklist. One of: top, bottom, or a positive number.", - optional: true, + propDefinition: [ + app, + "pos", + ], }, checked: { type: "boolean", + label: "Checked", description: "Determines whether the check item is already checked when created.", optional: true, }, }, + methods: { + createChecklistItem({ + checklistId, ...args + } = {}) { + return this.app.post({ + path: `/checklists/${checklistId}/checkItems`, + ...args, + }); + }, + }, async run({ $ }) { - const oauthSignerUri = this.trello.$auth.oauth_signer_uri; - - let id = this.id; - const trelloParams = [ - "name", - "pos", - "checked", - ]; - let p = this; - - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`) - .join("&"); - - const config = { - url: `https://api.trello.com/1/checklists/${id}/checkItems?${queryString}`, - method: "POST", - data: "", - }; + const { + createChecklistItem, + checklistId, + name, + pos, + checked, + } = this; - const token = { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }; + const response = await createChecklistItem({ + $, + checklistId, + params: { + name, + pos, + checked, + }, + }); - const signConfig = { - token, - oauthSignerUri, - }; + $.export("$summary", "Successfully created a checklist item"); - const resp = await axios($, config, signConfig); - return resp; + return response; }, }; diff --git a/components/trello/actions/create-checklist/create-checklist.mjs b/components/trello/actions/create-checklist/create-checklist.mjs index 2aaa04dfda5cb..722cbfa4d3be1 100644 --- a/components/trello/actions/create-checklist/create-checklist.mjs +++ b/components/trello/actions/create-checklist/create-checklist.mjs @@ -4,20 +4,20 @@ export default { ...common, key: "trello-create-checklist", name: "Create Checklist", - description: "Creates a checklist on the specified card. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-checklists/#api-checklists-post)", - version: "0.0.3", + description: "Creates a checklist on the specified card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-checklists/#api-checklists-post).", + version: "0.1.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, idCard: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -30,21 +30,22 @@ export default { }, name: { propDefinition: [ - common.props.trello, + common.props.app, "name", ], description: "The name of the checklist. Should be a string of length 1 to 16384.", }, pos: { propDefinition: [ - common.props.trello, + common.props.app, "pos", ], description: "The position of the new checklist. Valid values: `top`, `bottom`, or a positive float.", }, idChecklistSource: { + optional: true, propDefinition: [ - common.props.trello, + common.props.app, "checklist", (c) => ({ board: c.board, @@ -52,14 +53,25 @@ export default { ], }, }, + methods: { + ...common.methods, + createChecklist(args = {}) { + return this.app.post({ + path: "/checklists", + ...args, + }); + }, + }, async run({ $ }) { - const opts = { - idCard: this.idCard, - name: this.name, - pos: this.pos, - idChecklistSource: this.idChecklistSource, - }; - const res = await this.trello.createChecklist(opts, $); + const res = await this.createChecklist({ + $, + params: { + idCard: this.idCard, + name: this.name, + pos: this.pos, + idChecklistSource: this.idChecklistSource, + }, + }); $.export("$summary", `Successfully created checklist ${res.name}`); return res; }, diff --git a/components/trello/actions/create-comment-on-card/create-comment-on-card.mjs b/components/trello/actions/create-comment-on-card/create-comment-on-card.mjs index cdab19a84e1cc..1055f203d8845 100644 --- a/components/trello/actions/create-comment-on-card/create-comment-on-card.mjs +++ b/components/trello/actions/create-comment-on-card/create-comment-on-card.mjs @@ -4,23 +4,23 @@ export default { ...common, key: "trello-create-comment-on-card", name: "Create Comment on Card", - description: "Creates a new comment on a card. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-actions-comments-post)", - version: "0.0.3", + description: "Creates a new comment on a card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-actions-comments-post).", + version: "0.1.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, - idCard: { + cardId: { propDefinition: [ - common.props.trello, + common.props.app, "cards", - (c) => ({ - board: c.board, + ({ board }) => ({ + board, }), ], type: "string", @@ -34,9 +34,26 @@ export default { description: "Text for the comment to be created.", }, }, + methods: { + ...common.methods, + createCommentOnCard({ + cardId, ...args + } = {}) { + return this.app.post({ + path: `/cards/${cardId}/actions/comments`, + ...args, + }); + }, + }, async run({ $ }) { - const res = await this.trello.createCommentOnCard(this.idCard, this.comment, $); - $.export("$summary", `Successfully added comment to card ${this.idCard}`); + const res = await this.createCommentOnCard({ + $, + cardId: this.cardId, + params: { + text: this.comment, + }, + }); + $.export("$summary", `Successfully added comment to card ${this.cardId}`); return res; }, }; diff --git a/components/trello/actions/create-label/create-label.mjs b/components/trello/actions/create-label/create-label.mjs index e17c3dbea8f43..6fd4a182d6ca0 100644 --- a/components/trello/actions/create-label/create-label.mjs +++ b/components/trello/actions/create-label/create-label.mjs @@ -1,23 +1,30 @@ -// legacy_hash_id: a_l0iLRL -import { axios } from "@pipedream/platform"; +import app from "../../trello.app.mjs"; export default { key: "trello-create-label", name: "Create Label", - description: "Creates a new label on the specified board.", - version: "0.1.3", + description: "Creates a new label on the specified board. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-labels/#api-labels-post).", + version: "0.2.0", type: "action", props: { - trello: { - type: "app", - app: "trello", + app, + idBoard: { + type: "string", + label: "Board ID", + description: "The ID of the board to create the label on.", + propDefinition: [ + app, + "board", + ], }, name: { type: "string", + label: "Name", description: "Name for the label.", }, color: { type: "string", + label: "Color", description: "The color for the label. One of: yellow, purple, blue, red, green, orange, black, sky, pink, lime, null (null means no color, and the label will not show on the front of cards)", options: [ "yellow", @@ -33,41 +40,35 @@ export default { "null", ], }, - idBoard: { - type: "string", - description: "The ID of the board to create the label on.", + }, + methods: { + createLabel(args = {}) { + return this.app.post({ + path: "/labels", + ...args, + }); }, }, async run({ $ }) { - const oauthSignerUri = this.trello.$auth.oauth_signer_uri; - - const trelloParams = [ - "name", - "color", - "idBoard", - ]; - let p = this; - - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`) - .join("&"); - const config = { - url: `https://api.trello.com/1/labels?${queryString}`, - method: "POST", - data: "", - }; + const { + createLabel, + idBoard, + name, + color, + } = this; - const token = { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }; + const response = await createLabel({ + $, + params: { + idBoard, + name, + color, + }, + }); - const signConfig = { - token, - oauthSignerUri, - }; + $.export("$summary", "Successfully created a label"); - const resp = await axios($, config, signConfig); - return resp; + return response; }, }; diff --git a/components/trello/actions/create-list/create-list.mjs b/components/trello/actions/create-list/create-list.mjs index c153b3d78db34..30a3add4509d9 100644 --- a/components/trello/actions/create-list/create-list.mjs +++ b/components/trello/actions/create-list/create-list.mjs @@ -1,67 +1,76 @@ -// legacy_hash_id: a_G1iBG7 -import { axios } from "@pipedream/platform"; +import app from "../../trello.app.mjs"; export default { key: "trello-create-list", name: "Create a List", - description: "Creates a new list on a board", - version: "0.1.3", + description: "Creates a new list. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-lists/#api-lists-post).", + version: "0.2.0", type: "action", props: { - trello: { - type: "app", - app: "trello", + app, + idBoard: { + type: "string", + label: "Board ID", + description: "The long ID of the board the list should be created on.", + propDefinition: [ + app, + "board", + ], }, name: { type: "string", + label: "Name", description: "Name for the list.", }, - idBoard: { - type: "string", - description: "The long ID of the board the list should be created on.", - }, idListSource: { type: "string", + label: "List Source ID", description: "ID of the list to copy into the new list.", optional: true, + propDefinition: [ + app, + "lists", + ({ idBoard }) => ({ + board: idBoard, + }), + ], }, pos: { - type: "string", - description: "Position of the list. top, bottom, or a positive floating point number.", - optional: true, + propDefinition: [ + app, + "pos", + ], + }, + }, + methods: { + createList(args = {}) { + return this.app.post({ + path: "/lists", + ...args, + }); }, }, async run({ $ }) { - const oauthSignerUri = this.trello.$auth.oauth_signer_uri; - - const trelloParams = [ - "name", - "idBoard", - "idListSource", - "pos", - ]; - let p = this; - - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`) - .join("&"); - - const config = { - url: `https://api.trello.com/1/lists?${queryString}`, - method: "POST", - data: "", - }; + const { + createList, + name, + idBoard, + idListSource, + pos, + } = this; - const token = { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }; + const response = await createList({ + $, + params: { + name, + idBoard, + idListSource, + pos, + }, + }); - const signConfig = { - token, - oauthSignerUri, - }; + $.export("$summary", "Successfully created list."); - const resp = await axios($, config, signConfig); - return resp; + return response; }, }; diff --git a/components/trello/actions/delete-checklist/delete-checklist.mjs b/components/trello/actions/delete-checklist/delete-checklist.mjs index 9b118a961aab2..6f8928216191d 100644 --- a/components/trello/actions/delete-checklist/delete-checklist.mjs +++ b/components/trello/actions/delete-checklist/delete-checklist.mjs @@ -4,20 +4,20 @@ export default { ...common, key: "trello-delete-checklist", name: "Delete Checklist", - description: "Deletes the specified checklist. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-checklists/#api-checklists-id-delete)", - version: "0.1.4", + description: "Deletes the specified checklist. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-checklists/#api-checklists-id-delete).", + version: "0.2.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, - idCard: { + carId: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -28,19 +28,32 @@ export default { description: "The ID of the card containing the checklist do delete", optional: false, }, - idChecklist: { + checklistId: { propDefinition: [ - common.props.trello, + common.props.app, "checklist", - (c) => ({ - card: c.idCard, + ({ carId }) => ({ + card: carId, }), ], description: "The ID of the checklist to delete", }, }, + methods: { + deleteChecklist({ + checklistId, ...args + } = {}) { + return this.app.delete({ + path: `/checklists/${checklistId}`, + ...args, + }); + }, + }, async run({ $ }) { - await this.trello.deleteChecklist(this.idChecklist, $); - $.export("$summary", `Successfully deleted checklist ${this.idChecklist}`); + await this.deleteChecklist({ + $, + checklistId: this.checklistId, + }); + $.export("$summary", `Successfully deleted checklist ${this.checklistId}`); }, }; diff --git a/components/trello/actions/find-labels/find-labels.mjs b/components/trello/actions/find-labels/find-labels.mjs index 76921fba9f552..c777387e1f693 100644 --- a/components/trello/actions/find-labels/find-labels.mjs +++ b/components/trello/actions/find-labels/find-labels.mjs @@ -4,39 +4,42 @@ export default { ...common, key: "trello-find-labels", name: "Find a Label", - description: "Finds a label on a specific board by name. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-labels-get)", - version: "0.1.4", + description: "Finds a label on a specific board by name. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-labels-get)", + version: "0.2.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], description: "Unique identifier of the board to search for labels", }, name: { propDefinition: [ - common.props.trello, + common.props.app, "name", ], label: "Label Name", description: "Name of the label to find.", optional: false, }, - labelLimit: { + limit: { type: "integer", - label: "Results", + label: "Limit", description: "The number of labels to be returned (up to 1000)", default: 50, }, }, async run({ $ }) { - const opts = { - limit: this.labelLimit, - }; - const labels = await this.trello.findLabel(this.board, opts, $); + const labels = await this.app.findLabel({ + $, + boardId: this.board, + params: { + limit: this.limit, + }, + }); const res = this.getMatches(labels, this.name); $.export("$summary", `Successfully retrieved ${res.length} label(s) with name ${this.name}`); return res; diff --git a/components/trello/actions/find-list/find-list.mjs b/components/trello/actions/find-list/find-list.mjs index 3b3ac4a5f02ea..e81364b5a242b 100644 --- a/components/trello/actions/find-list/find-list.mjs +++ b/components/trello/actions/find-list/find-list.mjs @@ -4,21 +4,21 @@ export default { ...common, key: "trello-find-list", name: "Find a List", - description: "Finds a list on a specific board by name. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-lists-get)", - version: "0.1.4", + description: "Finds a list on a specific board by name. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-lists-get).", + version: "0.2.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], description: "Specify the board to search for lists", }, name: { propDefinition: [ - common.props.trello, + common.props.app, "name", ], label: "List Name", @@ -27,7 +27,7 @@ export default { }, listFilter: { propDefinition: [ - common.props.trello, + common.props.app, "listFilter", ], }, @@ -38,10 +38,13 @@ export default { name, listFilter, } = this; - const opts = { - filter: listFilter, - }; - const lists = await this.trello.findList(board, opts, $); + const lists = await this.app.getLists({ + $, + boardId: board, + params: { + filter: listFilter, + }, + }); const res = this.getMatches(lists, name); $.export("$summary", `Successfully retrieved ${res.length} list(s) with name ${name}`); return res; diff --git a/components/trello/actions/get-card/get-card.mjs b/components/trello/actions/get-card/get-card.mjs index be8f24213a55a..2f2d45466f2a7 100644 --- a/components/trello/actions/get-card/get-card.mjs +++ b/components/trello/actions/get-card/get-card.mjs @@ -4,20 +4,20 @@ export default { ...common, key: "trello-get-card", name: "Get Card", - description: "Gets a card by its ID. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-get)", - version: "0.1.7", + description: "Gets a card by its ID. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-get).", + version: "0.2.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, cardId: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -30,15 +30,19 @@ export default { }, customFieldItems: { propDefinition: [ - common.props.trello, + common.props.app, "customFieldItems", ], }, }, async run({ $ }) { - const res = await this.trello.getCard(this.cardId, { - customFieldItems: this.customFieldItems, - }, $); + const res = await this.app.getCard({ + $, + cardId: this.cardId, + params: { + customFieldItems: this.customFieldItems, + }, + }); $.export("$summary", `Successfully retrieved card ${this.cardId}`); return res; }, diff --git a/components/trello/actions/get-list/get-list.mjs b/components/trello/actions/get-list/get-list.mjs index 2815fbacb4403..038d12503be5b 100644 --- a/components/trello/actions/get-list/get-list.mjs +++ b/components/trello/actions/get-list/get-list.mjs @@ -1,32 +1,46 @@ -import { axios } from "@pipedream/platform"; +import app from "../../trello.app.mjs"; export default { key: "trello-get-list", name: "Get List", - description: "Get information about a List", - version: "0.0.4", + description: "Get information about a List. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-lists/#api-lists-id-get).", + version: "0.1.0", type: "action", props: { - // eslint-disable-next-line pipedream/props-label, pipedream/props-description - trello: { - type: "app", - app: "trello", + app, + boardId: { + propDefinition: [ + app, + "board", + ], }, listId: { type: "string", label: "List ID", description: "The ID of the Trello list", + optional: false, + propDefinition: [ + app, + "lists", + ({ boardId }) => ({ + board: boardId, + }), + ], }, }, async run({ $ }) { - return await axios($, { - url: `https://api.trello.com/1/lists/${this.listId}`, - }, { - token: { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }, - oauthSignerUri: this.trello.$auth.oauth_signer_uri, + const { + app, + listId, + } = this; + + const response = await app.getList({ + $, + listId, }); + + $.export("$summary", `Successfully retrieved list ${listId}.`); + + return response; }, }; diff --git a/components/trello/actions/move-card-to-list/move-card-to-list.mjs b/components/trello/actions/move-card-to-list/move-card-to-list.mjs index 4f964403db985..a5507158b921b 100644 --- a/components/trello/actions/move-card-to-list/move-card-to-list.mjs +++ b/components/trello/actions/move-card-to-list/move-card-to-list.mjs @@ -4,20 +4,20 @@ export default { ...common, key: "trello-move-card-to-list", name: "Move Card to List", - description: "Moves a card to the specified board/list pair. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put)", - version: "0.1.4", + description: "Moves a card to the specified board/list pair. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put).", + version: "0.2.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, - idCard: { + cardId: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -28,9 +28,9 @@ export default { description: "The ID of the card to move", optional: false, }, - toIdList: { + idList: { propDefinition: [ - common.props.trello, + common.props.app, "lists", (c) => ({ board: c.board, @@ -43,11 +43,15 @@ export default { }, }, async run({ $ }) { - const res = await this.trello.moveCardToList(this.idCard, { - idBoard: this.board, - idList: this.toIdList, - }, $); - $.export("$summary", `Successfully moved card ${this.idCard} to list ${this.toIdList}`); + const res = await this.app.updateCard({ + $, + cardId: this.cardId, + data: { + idBoard: this.board, + idList: this.idList, + }, + }); + $.export("$summary", `Successfully moved card ${this.cardId} to list ${this.idList}`); return res; }, }; diff --git a/components/trello/actions/remove-label-from-card/remove-label-from-card.mjs b/components/trello/actions/remove-label-from-card/remove-label-from-card.mjs index d87c6cd641555..7a4be7c28728a 100644 --- a/components/trello/actions/remove-label-from-card/remove-label-from-card.mjs +++ b/components/trello/actions/remove-label-from-card/remove-label-from-card.mjs @@ -4,20 +4,20 @@ export default { ...common, key: "trello-remove-label-from-card", name: "Remove Card Label", - description: "Removes label from card. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idlabels-idlabel-delete)", - version: "0.1.4", + description: "Removes label from card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idlabels-idlabel-delete).", + version: "0.2.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, - idCard: { + cardId: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -28,9 +28,9 @@ export default { description: "The ID of the Card to remove the Label from", optional: false, }, - idLabel: { + labelId: { propDefinition: [ - common.props.trello, + common.props.app, "label", (c) => ({ board: c.board, @@ -39,9 +39,25 @@ export default { description: "The ID of the Label to be removed from the card.", }, }, + methods: { + removeLabelFromCard({ + cardId, labelId, ...args + } = {}) { + return this.app.delete({ + path: `/cards/${cardId}/idLabels/${labelId}`, + ...args, + }); + }, + }, async run({ $ }) { - const res = await this.trello.removeLabelFromCard(this.idCard, this.idLabel, $); - $.export("$summary", `Successfully removed label ${this.idLabel} from card ${this.idCard}`); - return res; + await this.removeLabelFromCard({ + $, + cardId: this.cardId, + labelId: this.labelId, + }); + $.export("$summary", "Successfully sent request to remove label from card."); + return { + success: true, + }; }, }; diff --git a/components/trello/actions/rename-list/rename-list.mjs b/components/trello/actions/rename-list/rename-list.mjs index 0319ef73d12d8..76cb72c0f00e3 100644 --- a/components/trello/actions/rename-list/rename-list.mjs +++ b/components/trello/actions/rename-list/rename-list.mjs @@ -4,20 +4,20 @@ export default { ...common, key: "trello-rename-list", name: "Rename List", - description: "Renames an existing list. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-lists/#api-lists-id-put)", - version: "0.0.3", + description: "Renames an existing list. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-lists/#api-lists-id-put).", + version: "0.1.0", type: "action", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, listId: { propDefinition: [ - common.props.trello, + common.props.app, "lists", (c) => ({ board: c.board, @@ -30,18 +30,32 @@ export default { }, name: { propDefinition: [ - common.props.trello, + common.props.app, "name", ], description: "The new name of the list", optional: false, }, }, + methods: { + renameList({ + listId, ...args + } = {}) { + return this.app.put({ + path: `/lists/${listId}`, + ...args, + }); + }, + }, async run({ $ }) { - const res = await this.trello.renameList(this.listId, { - name: this.name, - }, $); - $.export("$summary", `Successfully renamed list to ${this.name}`); + const res = await this.renameList({ + $, + listId: this.listId, + data: { + name: this.name, + }, + }); + $.export("$summary", `Successfully renamed list to \`${this.name}\`.`); return res; }, }; diff --git a/components/trello/actions/search-boards/search-boards.mjs b/components/trello/actions/search-boards/search-boards.mjs index b3c90d4840a48..e324ab52ba9f2 100644 --- a/components/trello/actions/search-boards/search-boards.mjs +++ b/components/trello/actions/search-boards/search-boards.mjs @@ -4,33 +4,33 @@ export default { ...common, key: "trello-search-boards", name: "Search Boards", - description: "Searches for boards matching the specified query. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-search/#api-search-get)", - version: "0.2.4", + description: "Searches for boards matching the specified query. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-search/#api-search-get).", + version: "0.3.0", type: "action", props: { ...common.props, query: { propDefinition: [ - common.props.trello, + common.props.app, "query", ], }, idOrganizations: { propDefinition: [ - common.props.trello, + common.props.app, "idOrganizations", ], description: "Specify the organizations to search for boards in", }, partial: { propDefinition: [ - common.props.trello, + common.props.app, "partial", ], }, boardFields: { propDefinition: [ - common.props.trello, + common.props.app, "boardFields", ], }, @@ -42,15 +42,17 @@ export default { }, }, async run({ $ }) { - const opts = { - query: this.query, - idOrganizations: this.idOrganizations, - modelTypes: "boards", - board_fields: this.boardFields.join(","), - boards_limit: this.boardsLimit, - partial: this.partial, - }; - const { boards } = await this.trello.searchBoards(opts, $); + const { boards } = await this.app.search({ + $, + params: { + query: this.query, + idOrganizations: this.idOrganizations?.join(","), + modelTypes: "boards", + board_fields: this.boardFields.join(","), + boards_limit: this.boardsLimit, + partial: this.partial, + }, + }); $.export("$summary", `Successfully retrieved ${boards.length} board(s)`); return boards; }, diff --git a/components/trello/actions/search-cards/search-cards.mjs b/components/trello/actions/search-cards/search-cards.mjs index 4dedab5969988..bce976526f035 100644 --- a/components/trello/actions/search-cards/search-cards.mjs +++ b/components/trello/actions/search-cards/search-cards.mjs @@ -4,20 +4,20 @@ export default { ...common, key: "trello-search-cards", name: "Search Cards", - description: "Searches for cards matching the specified query. [See the docs here](https://developer.atlassian.com/cloud/trello/rest/api-group-search/#api-search-get)", - version: "0.1.4", + description: "Searches for cards matching the specified query. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-search/#api-search-get).", + version: "0.2.0", type: "action", props: { ...common.props, query: { propDefinition: [ - common.props.trello, + common.props.app, "query", ], }, idBoards: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], type: "string[]", @@ -26,13 +26,13 @@ export default { }, partial: { propDefinition: [ - common.props.trello, + common.props.app, "partial", ], }, cardFields: { propDefinition: [ - common.props.trello, + common.props.app, "cardFields", ], }, @@ -44,15 +44,17 @@ export default { }, }, async run({ $ }) { - const opts = { - query: this.query, - idBoards: this.idBoards, - modelTypes: "cards", - card_fields: this.cardFields, - cards_limit: this.cardsLimit, - partial: this.partial, - }; - const { cards } = await this.trello.searchCards(opts, $); + const { cards } = await this.app.search({ + $, + params: { + query: this.query, + idBoards: this.idBoards, + modelTypes: "cards", + card_fields: this.cardFields, + cards_limit: this.cardsLimit, + partial: this.partial, + }, + }); $.export("$summary", `Successfully retrieved ${cards.length} card(s)`); return cards; }, diff --git a/components/trello/actions/search-checklists/search-checklists.mjs b/components/trello/actions/search-checklists/search-checklists.mjs index 0d1e427cf76d7..e51b0314ccda7 100644 --- a/components/trello/actions/search-checklists/search-checklists.mjs +++ b/components/trello/actions/search-checklists/search-checklists.mjs @@ -1,35 +1,43 @@ -// legacy_hash_id: a_1WiqM5 -import { axios } from "@pipedream/platform"; +import app from "../../trello.app.mjs"; export default { key: "trello-search-checklists", name: "Find Checklist", - description: "Find a checklist on a particular board or card by name.", - version: "0.1.3", + description: "Find a checklist on a particular board or card by name. [See the documentation here](https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-checklists-get) and [here](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-checklists-get).", + version: "0.2.0", type: "action", props: { - trello: { - type: "app", - app: "trello", - }, + app, type: { type: "string", + label: "Type", description: "Whether to search boards or cards for the checklist.", options: [ "board", "card", ], + reloadProps: true, + }, + boardId: { + type: "string", + label: "Board ID", + description: "The ID of the board.", + hidden: true, }, - id: { + cardId: { type: "string", - description: "The ID of the board or card.", + label: "Card ID", + description: "The ID of the card.", + hidden: true, }, query: { type: "string", + label: "Query", description: "The query to search for.", }, checkItems: { type: "string", + label: "Check Items", description: "all or none", optional: true, options: [ @@ -37,7 +45,7 @@ export default { "none", ], }, - checkItem_fields: { + checkItemFields: { type: "string", label: "CheckItem Fields", description: "all or a comma-separated list of: name, nameData, pos, state, type", @@ -45,6 +53,7 @@ export default { }, filter: { type: "string", + label: "Filter", description: "all or none", optional: true, options: [ @@ -54,53 +63,100 @@ export default { }, fields: { type: "string", - description: "all or a comma-separated list of: idBoard, idCard, name, pos", + label: "Fields", + description: "`all` or a comma-separated list of: `idBoard`, `idCard`, `name`, `pos`. Eg: `idBoard,idCard,name,pos`. Eg: `all`.", optional: true, }, }, + additionalProps() { + const { type } = this; + + const defaultProps = { + boardId: { + type: "string", + label: "Board ID", + description: "The ID of the board.", + hidden: false, + options: async () => { + const boards = await this.app.getBoards(); + return boards + .filter(({ closed }) => closed === false) + .map(({ + id: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + }; + + if (type === "card") { + return { + ...defaultProps, + cardId: { + type: "string", + label: "Card ID", + description: "The ID of the card.", + hidden: false, + options: async () => { + const cards = await this.app.getCards({ + boardId: this.boardId, + }); + return cards.map(({ + id: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + }; + } + + return defaultProps; + }, async run({ $ }) { - let type = this.type; - let id = this.id; - let query = this.query; - const trelloParams = [ - "checkItems", - "checkItem_fields", - "filter", - "fields", - ]; - let p = this; + const { + app, + type, + boardId, + cardId, + query, + checkItems, + checkItemFields, + filter, + fields, + } = this; + let checklists = null; let matches = []; - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`) - .join("&"); + const params = { + checkItems, + checkItem_fields: checkItemFields, + filter, + fields, + }; - if (type == "board") { - checklists = await axios($, { - url: `https://api.trello.com/1/boards/${id}/checklists?${queryString}`, - method: "GET", - }, { - token: { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }, - oauthSignerUri: this.trello.$auth.oauth_signer_uri, + if (type === "board") { + checklists = await app.listBoardChecklists({ + $, + boardId, + params, }); - } else if (type == "card") { - checklists = await axios($, { - url: `https://api.trello.com/1/cards/${id}/checklists?${queryString}`, - method: "GET", - }, { - token: { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, - }, - oauthSignerUri: this.trello.$auth.oauth_signer_uri, + + } else if (type === "card") { + checklists = await app.listCardChecklists({ + $, + cardId, + params, }); } + if (checklists) { - checklists.forEach(function(checklist) { - if (checklist.name.includes(query)) + checklists.forEach((checklist) => { + if (checklist.name?.toLowerCase().includes(query.toLowerCase())) matches.push(checklist); }); } diff --git a/components/trello/actions/search-members/search-members.mjs b/components/trello/actions/search-members/search-members.mjs index f87da7de8f0fd..3c70aaef309cb 100644 --- a/components/trello/actions/search-members/search-members.mjs +++ b/components/trello/actions/search-members/search-members.mjs @@ -1,61 +1,81 @@ -// legacy_hash_id: a_8KiV84 -import { axios } from "@pipedream/platform"; +import app from "../../trello.app.mjs"; export default { key: "trello-search-members", name: "Search Members", - description: "Search for Trello members.", - version: "0.1.3", + description: "Search for Trello members. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-search/#api-search-members-get).", + version: "0.2.0", type: "action", props: { - trello: { - type: "app", - app: "trello", - }, + app, query: { type: "string", + label: "Search Query", description: "Search query 1 to 16384 characters long", }, limit: { type: "integer", + label: "Limit", description: "The maximum number of results to return. Maximum of 20.", optional: true, }, idBoard: { - type: "string", + label: "Board ID", + description: "The ID of the board to search for members.", optional: true, + propDefinition: [ + app, + "board", + ], }, idOrganization: { type: "string", + label: "Organization ID", + description: "The ID of the organization to search for members.", optional: true, + propDefinition: [ + app, + "idOrganizations", + ], }, onlyOrgMembers: { type: "boolean", + label: "Only Organization Members", + description: "If true, only members of the organization will be returned.", optional: true, }, }, + methods: { + searchMembers(args = {}) { + return this.app._makeRequest({ + path: "/search/members", + ...args, + }); + }, + }, async run({ $ }) { - const trelloParams = [ - "query", - "limit", - "idBoard", - "idOrganization", - "onlyOrgMembers", - ]; - let p = this; + const { + searchMembers, + query, + limit, + idBoard, + idOrganization, + onlyOrgMembers, + } = this; - const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`) - .join("&"); - - return await axios($, { - url: `https://api.trello.com/1/search/members?${queryString}`, - method: "GET", - }, { - token: { - key: this.trello.$auth.oauth_access_token, - secret: this.trello.$auth.oauth_refresh_token, + const response = await searchMembers({ + $, + params: { + query, + limit, + idBoard, + idOrganization, + onlyOrgMembers, }, - oauthSignerUri: this.trello.$auth.oauth_signer_uri, }); + + $.export("$summary", "Successfully searched for members."); + + return response; }, }; diff --git a/components/trello/actions/update-card/update-card.mjs b/components/trello/actions/update-card/update-card.mjs index 2fae90430c74e..10b14d59219f5 100644 --- a/components/trello/actions/update-card/update-card.mjs +++ b/components/trello/actions/update-card/update-card.mjs @@ -6,20 +6,20 @@ export default { ...common, key: "trello-update-card", name: "Update Card", - description: "Updates a card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put)", - version: "0.1.5", + description: "Updates a card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put).", + version: "0.2.0", type: "action", props: { ...common.props, idBoard: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, - idCard: { + cardId: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.idBoard, @@ -32,14 +32,14 @@ export default { }, name: { propDefinition: [ - common.props.trello, + common.props.app, "name", ], description: "The new name for the card.", }, desc: { propDefinition: [ - common.props.trello, + common.props.app, "desc", ], description: "The new description for the card.", @@ -52,7 +52,7 @@ export default { }, idMembers: { propDefinition: [ - common.props.trello, + common.props.app, "member", (c) => ({ board: c.idBoard, @@ -64,15 +64,20 @@ export default { optional: true, }, idAttachmentCover: { - type: "string", - label: "Cover", - description: - "Assign an attachment to be the cover image for the card", - optional: true, + propDefinition: [ + common.props.app, + "cardAttachmentId", + ({ cardId }) => ({ + cardId, + params: { + filter: "cover", + }, + }), + ], }, idList: { propDefinition: [ - common.props.trello, + common.props.app, "lists", (c) => ({ board: c.idBoard, @@ -84,7 +89,7 @@ export default { }, idLabels: { propDefinition: [ - common.props.trello, + common.props.app, "label", (c) => ({ board: c.idBoard, @@ -97,19 +102,19 @@ export default { }, pos: { propDefinition: [ - common.props.trello, + common.props.app, "pos", ], }, due: { propDefinition: [ - common.props.trello, + common.props.app, "due", ], }, dueComplete: { propDefinition: [ - common.props.trello, + common.props.app, "dueComplete", ], description: "Whether the due date should be marked complete.", @@ -123,25 +128,25 @@ export default { }, address: { propDefinition: [ - common.props.trello, + common.props.app, "address", ], }, locationName: { propDefinition: [ - common.props.trello, + common.props.app, "locationName", ], }, coordinates: { propDefinition: [ - common.props.trello, + common.props.app, "coordinates", ], }, customFieldIds: { propDefinition: [ - common.props.trello, + common.props.app, "customFieldIds", (c) => ({ boardId: c.idBoard, @@ -156,7 +161,9 @@ export default { return props; } for (const customFieldId of this.customFieldIds) { - const customField = await this.trello.getCustomField(customFieldId); + const customField = await this.app.getCustomField({ + customFieldId, + }); props[customFieldId] = { type: "string", label: `Value for Custom Field - ${customField.name}`, @@ -175,7 +182,10 @@ export default { async getCustomFieldItems($) { const customFieldItems = []; for (const customFieldId of this.customFieldIds) { - const customField = await this.trello.getCustomField(customFieldId, $); + const customField = await this.app.getCustomField({ + $, + customFieldId, + }); const customFieldItem = { idCustomField: customFieldId, }; @@ -196,30 +206,37 @@ export default { }, }, async run({ $ }) { - const opts = pickBy(pick(this, [ - "name", - "desc", - "closed", - "idMembers", - "idAttachmentCover", - "idList", - "idLabels", - "idBoard", - "pos", - "due", - "dueComplete", - "subscribed", - "address", - "locationName", - "coordinates", - ])); - const res = await this.trello.updateCard(this.idCard, opts, $); + const res = await this.app.updateCard({ + $, + cardId: this.cardId, + data: pickBy(pick(this, [ + "name", + "desc", + "closed", + "idMembers", + "idAttachmentCover", + "idList", + "idLabels", + "idBoard", + "pos", + "due", + "dueComplete", + "subscribed", + "address", + "locationName", + "coordinates", + ])), + }); if (this.customFieldIds) { const customFieldItems = await this.getCustomFieldItems($); - const updatedCustomFields = await this.trello.updateCustomFields(this.idCard, { - customFieldItems, - }, $); + const updatedCustomFields = await this.app.updateCustomFields({ + $, + cardId: this.cardId, + data: { + customFieldItems, + }, + }); res.updatedCustomFields = updatedCustomFields; } diff --git a/components/trello/package.json b/components/trello/package.json index 699627582c090..68799271364e9 100644 --- a/components/trello/package.json +++ b/components/trello/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/trello", - "version": "0.3.14", + "version": "0.4.0", "description": "Pipedream Trello Components", "main": "trello.app.mjs", "keywords": [ @@ -10,10 +10,11 @@ "homepage": "https://pipedream.com/apps/trello", "author": "Pipedream (https://pipedream.com/)", "dependencies": { - "@pipedream/platform": "^1.5.1", + "@pipedream/platform": "^3.0.1", "crypto": "^1.0.1", + "form-data": "^4.0.0", "lodash-es": "^4.17.21", - "mime": "^3.0.0" + "ms": "^2.1.3" }, "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535", "publishConfig": { diff --git a/components/trello/sources/card-archived/card-archived.mjs b/components/trello/sources/card-archived/card-archived.mjs index a64935686ef10..3a9a793eb5d25 100644 --- a/components/trello/sources/card-archived/card-archived.mjs +++ b/components/trello/sources/card-archived/card-archived.mjs @@ -5,19 +5,20 @@ export default { key: "trello-card-archived", name: "Card Archived (Instant)", description: "Emit new event for each card archived.", - version: "0.0.13", + version: "0.1.0", type: "source", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, lists: { + optional: true, propDefinition: [ - common.props.trello, + common.props.app, "lists", (c) => ({ board: c.board, @@ -27,8 +28,21 @@ export default { }, methods: { ...common.methods, + getFilteredCards({ + boardId, ...args + } = {}) { + return this.app._makeRequest({ + path: `/boards/${boardId}/cards`, + ...args, + }); + }, async getSampleEvents() { - const cards = await this.trello.getFilteredCards(this.board, "closed"); + const cards = await this.getFilteredCards({ + boardId: this.board, + params: { + filter: "closed", + }, + }); return { sampleEvents: cards, sortField: "dateLastActivity", @@ -40,7 +54,9 @@ export default { }, async getResult(event) { const cardId = event.body?.action?.data?.card?.id; - return this.trello.getCard(cardId); + return this.app.getCard({ + cardId, + }); }, isRelevant({ result: card }) { return ( diff --git a/components/trello/sources/card-due-date-reminder/card-due-date-reminder.mjs b/components/trello/sources/card-due-date-reminder/card-due-date-reminder.mjs index d3a73dbbe98a7..6e7638180213d 100644 --- a/components/trello/sources/card-due-date-reminder/card-due-date-reminder.mjs +++ b/components/trello/sources/card-due-date-reminder/card-due-date-reminder.mjs @@ -1,3 +1,4 @@ +import ms from "ms"; import common from "../common/common-polling.mjs"; export default { @@ -5,46 +6,37 @@ export default { key: "trello-card-due-date-reminder", name: "Card Due Date Reminder", description: "Emit new event at a specified time before a card is due.", - version: "0.0.10", + version: "0.1.0", type: "source", dedupe: "unique", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, timeBefore: { - type: "integer", + type: "string", label: "Time Before", - description: "How far before the due time the event should trigger.", - default: 5, - }, - timeBeforeUnit: { - type: "integer", - label: "Time Before (Unit)", - description: "Unit of time for Time Before.", + description: "How far before the due time the event should trigger. For example, `5 minutes`, `10 minutes`, `1 hour`.", + default: "5 minutes", options: [ - { - label: "Minutes", - value: 60000, - }, - { - label: "Hours", - value: 3600000, - }, - { - label: "Days", - value: 86400000, - }, - { - label: "Weeks", - value: 604800000, - }, + "5 minutes", + "10 minutes", + "15 minutes", + "30 minutes", + "1 hour", + "2 hours", + "3 hours", + "6 hours", + "12 hours", + "1 day", + "2 days", + "3 days", + "1 week", ], - default: 60000, }, }, methods: { @@ -67,11 +59,20 @@ export default { const boardId = this.board; const now = event.timestamp * 1000; - const cards = await this.trello.getCards(boardId); + const timeBeforeMs = ms(this.timeBefore); + if (!timeBeforeMs) { + throw new Error(`Invalid timeBefore value: ${this.timeBefore}`); + } + + const cards = await this.app.getCards({ + boardId, + }); for (const card of cards) { - if (!card.due) continue; + if (!card.due) { + continue; + } const due = Date.parse(card.due); - const notifyAt = due - this.timeBefore * this.timeBeforeUnit; + const notifyAt = due - timeBeforeMs; if (notifyAt <= now) { this.emitEvent(card, now); } diff --git a/components/trello/sources/card-moved/card-moved.mjs b/components/trello/sources/card-moved/card-moved.mjs index 9e21985c6beeb..a6f03826eec10 100644 --- a/components/trello/sources/card-moved/card-moved.mjs +++ b/components/trello/sources/card-moved/card-moved.mjs @@ -5,19 +5,19 @@ export default { key: "trello-card-moved", name: "Card Moved (Instant)", description: "Emit new event each time a card is moved to a list.", - version: "0.0.12", + version: "0.1.0", type: "source", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, lists: { propDefinition: [ - common.props.trello, + common.props.app, "lists", (c) => ({ board: c.board, @@ -29,8 +29,12 @@ export default { ...common.methods, async getSampleEvents() { const cards = this.lists && this.lists.length > 0 - ? await this.trello.getCardsInList(this.lists[0]) - : await this.trello.getCards(this.board); + ? await this.app.getCardsInList({ + listId: this.lists[0], + }) + : await this.app.getCards({ + boardId: this.board, + }); return { sampleEvents: cards, sortFilter: "dateLastActivity", @@ -51,7 +55,9 @@ export default { const listAfter = event.body?.action?.data?.listAfter?.name; /** Record listAfter to use in generateMeta() */ this._setListAfter(listAfter); - return this.trello.getCard(cardId); + return this.app.getCard({ + cardId, + }); }, isRelevant({ result: card, event, diff --git a/components/trello/sources/card-updates/card-updates.mjs b/components/trello/sources/card-updates/card-updates.mjs index fd881c37e4892..8dc0abdc27dea 100644 --- a/components/trello/sources/card-updates/card-updates.mjs +++ b/components/trello/sources/card-updates/card-updates.mjs @@ -5,19 +5,19 @@ export default { key: "trello-card-updates", name: "Card Updates (Instant)", description: "Emit new event for each update to a Trello card.", - version: "0.0.12", + version: "0.1.0", type: "source", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, cards: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -26,7 +26,7 @@ export default { }, customFieldItems: { propDefinition: [ - common.props.trello, + common.props.app, "customFieldItems", ], }, @@ -37,14 +37,20 @@ export default { let cards = []; if (this.cards && this.cards.length > 0) { for (const cardId of this.cards) { - const card = await this.trello.getCard(cardId, { - customFieldItems: this.customFieldItems, + const card = await this.app.getCard({ + cardId, + params: { + customFieldItems: this.customFieldItems, + }, }); cards.push(card); } } else { - cards = await this.trello.getCards(this.board, { - customFieldItems: this.customFieldItems, + cards = await this.app.getCards({ + boardId: this.board, + params: { + customFieldItems: this.customFieldItems, + }, }); } return { @@ -58,8 +64,11 @@ export default { }, async getResult(event) { const cardId = event.body?.action?.data?.card?.id; - return this.trello.getCard(cardId, { - customFieldItems: this.customFieldItems, + return this.app.getCard({ + cardId, + params: { + customFieldItems: this.customFieldItems, + }, }); }, isRelevant({ result: card }) { diff --git a/components/trello/sources/common/common-board-based.mjs b/components/trello/sources/common/common-board-based.mjs index 1dfded0235aac..f200f0e3216ab 100644 --- a/components/trello/sources/common/common-board-based.mjs +++ b/components/trello/sources/common/common-board-based.mjs @@ -9,7 +9,7 @@ export default { ...base.props, board: { propDefinition: [ - base.props.trello, + base.props.app, "board", ], }, @@ -32,7 +32,9 @@ export default { return false; } - const member = await this.trello.getMember("me"); + const member = await this.app.getMember({ + memberId: "me", + }); if ( this.onlyEventsRelatedWithAuthenticatedUser && diff --git a/components/trello/sources/common/common-webhook.mjs b/components/trello/sources/common/common-webhook.mjs index ecd936dd20c72..955f74f169070 100644 --- a/components/trello/sources/common/common-webhook.mjs +++ b/components/trello/sources/common/common-webhook.mjs @@ -1,3 +1,4 @@ +import { createHmac } from "crypto"; import common from "./common.mjs"; export default { @@ -20,40 +21,68 @@ export default { }, async activate() { const modelId = await this.getModelId(); - const { id } = await this.trello.createHook({ - id: modelId, - endpoint: this.http.endpoint, + const { id } = await this.createHook({ + params: { + idModel: modelId, + description: "Pipedream Source ID", + callbackURL: this.http.endpoint, + }, }); this.db.set("hookId", id); }, async deactivate() { const hookId = this.db.get("hookId"); - await this.trello.deleteHook({ + await this.deleteHook({ hookId, }); }, }, methods: { ...common.methods, + getBase64Digest(data) { + const { secret } = this.app.getToken(); + return createHmac("sha1", secret) + .update(data) + .digest("base64"); + }, + // Do not remove the async keyword from this function + async isValidSignature({ + body, bodyRaw, headers, + }) { + const data = bodyRaw + body.webhook?.callbackURL; + const doubleHash = this.getBase64Digest(data); + const headerHash = headers["x-trello-webhook"]; + return doubleHash === headerHash; + }, + createHook(args = {}) { + return this.app.post({ + ...args, + debug: true, + path: "/webhooks/", + }); + }, + deleteHook({ + hookId, ...args + } = {}) { + return this.app.delete({ + ...args, + debug: true, + path: `/webhooks/${hookId}`, + }); + }, /** * Returns the ID of the current board selected. If no board is selected, returns * the id of the authenticated user. */ async getModelId() { - if (this.board) return this.board; - const member = await this.trello.getMember("me"); + if (this.board) { + return this.board; + } + const member = await this.app.getMember({ + memberId: "me", + }); return member.id; }, - /** - * Verifies that the event received was sent from Trello. - * @param {object} event - The event returned from a webhook - */ - verifyEvent(event) { - return ( - this.trello.verifyTrelloWebhookRequest(event, this.http.endpoint) && - event.body !== undefined - ); - }, /** * Default isCorrectEventType. Used in components to verify that the event received is * of the type that the component is watching for. @@ -73,17 +102,31 @@ export default { }, }, async run(event) { - if (!this.verifyEvent(event)) { + if (event.body === undefined) { + console.log("Event body is undefined. Skipping..."); + return; + } + + if (!this.isValidSignature(event)) { console.log("The event failed the verification. Skipping..."); return; } - if (!this.isCorrectEventType(event)) return; + + if (!this.isCorrectEventType(event)) { + console.log("The event is not of the correct type. Skipping..."); + return; + } const result = await this.getResult(event); - if (!(await this.isRelevant({ + const isRelevant = await this.isRelevant({ result, event, - }))) return; + }); + + if (!isRelevant) { + console.log("The event is not relevant. Skipping..."); + return; + } this.emitEvent(result); }, diff --git a/components/trello/sources/common/common.mjs b/components/trello/sources/common/common.mjs index 306d5d187747a..4beadb003d495 100644 --- a/components/trello/sources/common/common.mjs +++ b/components/trello/sources/common/common.mjs @@ -1,8 +1,8 @@ -import trello from "../../trello.app.mjs"; +import app from "../../trello.app.mjs"; export default { props: { - trello, + app, db: "$.service.db", }, methods: { diff --git a/components/trello/common/events.mjs b/components/trello/sources/common/events.mjs similarity index 100% rename from components/trello/common/events.mjs rename to components/trello/sources/common/events.mjs diff --git a/components/trello/sources/custom-webhook-events/custom-webhook-events.mjs b/components/trello/sources/custom-webhook-events/custom-webhook-events.mjs index b684fe4ecd107..7270389de9a46 100644 --- a/components/trello/sources/custom-webhook-events/custom-webhook-events.mjs +++ b/components/trello/sources/custom-webhook-events/custom-webhook-events.mjs @@ -1,29 +1,31 @@ import common from "../common/common-webhook.mjs"; +import events from "../common/events.mjs"; export default { ...common, key: "trello-custom-webhook-events", name: "Custom Webhook Events (Instant)", description: "Emit new events for activity matching a board, event types, lists and/or cards.", - version: "0.0.11", + version: "0.1.0", type: "source", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, eventTypes: { - propDefinition: [ - common.props.trello, - "eventTypes", - ], + type: "string[]", + label: "Event Types", + optional: true, + description: "Only emit events for the selected event types (e.g., `updateCard`).", + options: events, }, lists: { propDefinition: [ - common.props.trello, + common.props.app, "lists", (c) => ({ board: c.board, @@ -32,7 +34,7 @@ export default { }, cards: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -58,11 +60,24 @@ export default { }, methods: { ...common.methods, + getCardList({ + cardId, ...args + } = {}) { + return this.app._makeRequest({ + path: `/cards/${cardId}/list`, + ...args, + }); + }, async getSampleEvents() { const eventTypes = this.eventTypes && this.eventTypes.length > 0 ? this.eventTypes.join(",") : null; - const actions = await this.trello.getBoardActivity(this.board, eventTypes); + const actions = await this.app.getBoardActivity({ + boardId: this.board, + params: { + filter: eventTypes, + }, + }); return { sampleEvents: actions, sortField: "date", @@ -84,8 +99,12 @@ export default { let listId = body.action?.data?.list?.id; const cardId = body.action?.data?.card?.id; // If listId not returned, see if we can get it from the cardId - if (cardId && !listId) - listId = (await this.trello.getCardList(cardId)).id; + if (cardId && !listId) { + const res = await this.app.getCardList({ + cardId, + }); + listId = res.id; + } return ( (!this.lists || this.lists.length === 0 || diff --git a/components/trello/sources/new-activity/new-activity.mjs b/components/trello/sources/new-activity/new-activity.mjs index 7987a9c4814bb..379178942976d 100644 --- a/components/trello/sources/new-activity/new-activity.mjs +++ b/components/trello/sources/new-activity/new-activity.mjs @@ -5,13 +5,13 @@ export default { key: "trello-new-activity", name: "New Activity (Instant)", description: "Emit new event for new activity on a board.", - version: "0.0.9", + version: "0.1.0", type: "source", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, @@ -35,7 +35,9 @@ export default { methods: { ...common.methods, async getSampleEvents() { - const actions = await this.trello.getBoardActivity(this.board); + const actions = await this.app.getBoardActivity({ + boardId: this.board, + }); return { sampleEvents: actions, sortField: "date", diff --git a/components/trello/sources/new-attachment/new-attachment.mjs b/components/trello/sources/new-attachment/new-attachment.mjs index 5a6eabd4eee76..b20c4432d97da 100644 --- a/components/trello/sources/new-attachment/new-attachment.mjs +++ b/components/trello/sources/new-attachment/new-attachment.mjs @@ -5,13 +5,13 @@ export default { key: "trello-new-attachment", name: "New Attachment (Instant)", description: "Emit new event for new attachment on a board.", - version: "0.0.9", + version: "0.1.0", type: "source", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, @@ -36,8 +36,21 @@ export default { }, methods: { ...common.methods, + getAttachment({ + cardId, attachmentId, ...args + } = {}) { + return this.app._makeRequest({ + path: `/cards/${cardId}/attachments/${attachmentId}`, + ...args, + }); + }, async getSampleEvents() { - const actions = await this.trello.getBoardActivity(this.board, "addAttachmentToCard"); + const actions = await this.app.getBoardActivity({ + boardId: this.board, + params: { + filter: "addAttachmentToCard", + }, + }); return { sampleEvents: actions, sortField: "date", @@ -50,7 +63,10 @@ export default { async getResult(event) { const cardId = event.body?.action?.data?.card?.id; const attachmentId = event.body?.action?.data?.attachment?.id; - return this.trello.getAttachment(cardId, attachmentId); + return this.getAttachment({ + cardId, + attachmentId, + }); }, isRelevant({ event }) { const boardId = event.body?.action?.data?.board?.id; diff --git a/components/trello/sources/new-board/new-board.mjs b/components/trello/sources/new-board/new-board.mjs index 92c0ecbc84e3e..30142c1740e33 100644 --- a/components/trello/sources/new-board/new-board.mjs +++ b/components/trello/sources/new-board/new-board.mjs @@ -5,13 +5,13 @@ export default { key: "trello-new-board", name: "New Board (Instant)", description: "Emit new event for each new board added.", - version: "0.0.13", + version: "0.1.0", type: "source", dedupe: "unique", methods: { ...common.methods, async getSampleEvents() { - const boards = await this.trello.getBoards(); + const boards = await this.app.getBoards(); return { sampleEvents: boards, sortField: "dateLastView", @@ -23,7 +23,9 @@ export default { }, async getResult(event) { const boardId = event.body?.action?.data?.board?.id; - return this.trello.getBoard(boardId); + return this.app.getBoard({ + boardId, + }); }, }, }; diff --git a/components/trello/sources/new-card/new-card.mjs b/components/trello/sources/new-card/new-card.mjs index d4edc2cf2e1c6..6abce3a370d09 100644 --- a/components/trello/sources/new-card/new-card.mjs +++ b/components/trello/sources/new-card/new-card.mjs @@ -5,20 +5,20 @@ export default { key: "trello-new-card", name: "New Card (Instant)", description: "Emit new event for each new Trello card on a board.", - version: "0.0.12", + version: "0.1.0", type: "source", dedupe: "unique", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, lists: { propDefinition: [ - common.props.trello, + common.props.app, "lists", (c) => ({ board: c.board, @@ -27,7 +27,7 @@ export default { }, customFieldItems: { propDefinition: [ - common.props.trello, + common.props.app, "customFieldItems", ], }, @@ -36,11 +36,17 @@ export default { ...common.methods, async getSampleEvents() { const cards = this.lists && this.lists.length > 0 - ? await this.trello.getCardsInList(this.lists[0], { - customFieldItems: this.customFieldItems, + ? await this.app.getCardsInList({ + listId: this.lists[0], + params: { + customFieldItems: this.customFieldItems, + }, }) - : await this.trello.getCards(this.board, { - customFieldItems: this.customFieldItems, + : await this.app.getCards({ + boardId: this.board, + params: { + customFieldItems: this.customFieldItems, + }, }); return { sampleEvents: cards, @@ -53,8 +59,11 @@ export default { }, async getResult(event) { const cardId = event.body?.action?.data?.card?.id; - return this.trello.getCard(cardId, { - customFieldItems: this.customFieldItems, + return this.app.getCard({ + cardId, + params: { + customFieldItems: this.customFieldItems, + }, }); }, isRelevant({ result: card }) { diff --git a/components/trello/sources/new-checklist/new-checklist.mjs b/components/trello/sources/new-checklist/new-checklist.mjs index cef57e9376f10..d30169a264b33 100644 --- a/components/trello/sources/new-checklist/new-checklist.mjs +++ b/components/trello/sources/new-checklist/new-checklist.mjs @@ -5,13 +5,23 @@ export default { key: "trello-new-checklist", name: "New Checklist (Instant)", description: "Emit new event for each new checklist added to a board.", - version: "0.0.14", + version: "0.1.0", type: "source", dedupe: "unique", methods: { ...common.methods, + getChecklist({ + checklistId, ...args + } = {}) { + return this.app._makeRequest({ + path: `/checklists/${checklistId}`, + ...args, + }); + }, async getSampleEvents() { - const checklists = await this.trello.listBoardChecklists(this.board); + const checklists = await this.app.listBoardChecklists({ + boardId: this.board, + }); return { sampleEvents: checklists, sortField: "id", @@ -23,7 +33,9 @@ export default { }, async getResult(event) { const checklistId = event.body?.action?.data?.checklist?.id; - return this.trello.getChecklist(checklistId); + return this.getChecklist({ + checklistId, + }); }, }, }; diff --git a/components/trello/sources/new-comment-added-to-card/new-comment-added-to-card.mjs b/components/trello/sources/new-comment-added-to-card/new-comment-added-to-card.mjs index e670b385d4006..eee422e1af23b 100644 --- a/components/trello/sources/new-comment-added-to-card/new-comment-added-to-card.mjs +++ b/components/trello/sources/new-comment-added-to-card/new-comment-added-to-card.mjs @@ -5,20 +5,20 @@ export default { key: "trello-new-comment-added-to-card", name: "New Comment Added to Card (Instant)", description: "Emit new event for each new comment added to a card.", - version: "0.1.2", + version: "0.2.0", type: "source", dedupe: "unique", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, cards: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -42,13 +42,28 @@ export default { }, methods: { ...common.methods, + getCardActivity({ + cardId, ...args + } = {}) { + return this.app._makeRequest({ + path: `/cards/${cardId}/actions`, + ...args, + }); + }, async getSampleEvents() { const cards = this.cards && this.cards.length > 0 ? this.cards - : (await this.trello.getCards(this.board)).map((card) => card.id); + : (await this.app.getCards({ + boardId: this.board, + })).map((card) => card.id); const actions = []; for (const card of cards) { - const activities = await this.trello.getCardActivity(card, "commentCard"); + const activities = await this.getCardActivity({ + cardId: card, + params: { + filter: "commentCard", + }, + }); for (const activity of activities) { actions.push(await this.getResult(activity)); @@ -64,10 +79,16 @@ export default { return eventType === "commentCard"; }, async getResult(event) { - const card = await this.trello.getCard(event?.body?.action?.data?.card?.id ?? - event?.data?.card?.id); - const member = await this.trello.getMember(event?.body?.action?.idMemberCreator ?? - event.idMemberCreator); + const cardId = event?.body?.action?.data?.card?.id ?? + event?.data?.card?.id; + const card = await this.app.getCard({ + cardId, + }); + const memberId = event?.body?.action?.idMemberCreator ?? + event.idMemberCreator; + const member = await this.app.getMember({ + memberId, + }); return { member, diff --git a/components/trello/sources/new-label-added-to-card/new-label-added-to-card.mjs b/components/trello/sources/new-label-added-to-card/new-label-added-to-card.mjs index 9b2e0d4869c72..9873325e372f4 100644 --- a/components/trello/sources/new-label-added-to-card/new-label-added-to-card.mjs +++ b/components/trello/sources/new-label-added-to-card/new-label-added-to-card.mjs @@ -5,19 +5,19 @@ export default { key: "trello-new-label-added-to-card", name: "New Label Added To Card (Instant)", description: "Emit new event for each label added to a card.", - version: "0.0.12", + version: "0.1.0", type: "source", props: { ...common.props, board: { propDefinition: [ - common.props.trello, + common.props.app, "board", ], }, lists: { propDefinition: [ - common.props.trello, + common.props.app, "lists", (c) => ({ board: c.board, @@ -26,7 +26,7 @@ export default { }, cards: { propDefinition: [ - common.props.trello, + common.props.app, "cards", (c) => ({ board: c.board, @@ -43,12 +43,16 @@ export default { } if (this.lists && this.lists.length > 0) { for (const listId of this.lists) { - const cards = await this.trello.getCardsInList(listId); + const cards = await this.app.getCardsInList({ + listId, + }); await this.emitLabelsFromCards(cards); } return; } - const cards = await this.trello.getCards(this.board); + const cards = await this.app.getCards({ + boardId: this.board, + }); await this.emitLabelsFromCards(cards); }, }, @@ -58,7 +62,9 @@ export default { for (const card of cards) { const labelIds = card.idLabels; for (const labelId of labelIds) { - const label = await this.trello.getLabel(labelId); + const label = await this.app.getLabel({ + labelId, + }); let summary = label.color; summary += label.name ? ` - ${label.name}` @@ -74,8 +80,10 @@ export default { }, async emitLabelsFromCardIds(cardIds) { const cards = []; - for (const id of cardIds) { - const card = await this.trello.getCard(id); + for (const cardId of cardIds) { + const card = await this.app.getCard({ + cardId, + }); cards.push(card); } await this.emitLabelsFromCards(cards); @@ -103,7 +111,9 @@ export default { /** Record labelName & labelColor to use in generateMeta() */ this._setLabelName(labelName); this._setLabelColor(labelColor); - return this.trello.getCard(cardId); + return this.app.getCard({ + cardId, + }); }, isRelevant({ result: card }) { return ( diff --git a/components/trello/sources/new-label/new-label.mjs b/components/trello/sources/new-label/new-label.mjs index 906fc138148c8..852949cdfa153 100644 --- a/components/trello/sources/new-label/new-label.mjs +++ b/components/trello/sources/new-label/new-label.mjs @@ -5,13 +5,15 @@ export default { key: "trello-new-label", name: "New Label (Instant)", description: "Emit new event for each new label added to a board.", - version: "0.0.14", + version: "0.1.0", type: "source", dedupe: "unique", methods: { ...common.methods, async getSampleEvents() { - const labels = await this.trello.findLabel(this.board); + const labels = await this.app.findLabel({ + boardId: this.board, + }); return { sampleEvents: labels, sortField: "id", @@ -23,7 +25,9 @@ export default { }, async getResult(event) { const labelId = event.body?.action?.data?.label?.id; - return this.trello.getLabel(labelId); + return this.app.getLabel({ + labelId, + }); }, generateMeta({ id, name, color: summary, diff --git a/components/trello/sources/new-list/new-list.mjs b/components/trello/sources/new-list/new-list.mjs index c27d0a77f5414..ad621793bcda1 100644 --- a/components/trello/sources/new-list/new-list.mjs +++ b/components/trello/sources/new-list/new-list.mjs @@ -5,13 +5,15 @@ export default { key: "trello-new-list", name: "New List (Instant)", description: "Emit new event for each new list added to a board.", - version: "0.0.14", + version: "0.1.0", type: "source", dedupe: "unique", methods: { ...common.methods, async getSampleEvents() { - const lists = await this.trello.getLists(this.board); + const lists = await this.app.getLists({ + boardId: this.board, + }); return { sampleEvents: lists, sortField: "id", @@ -23,7 +25,9 @@ export default { }, async getResult(event) { const listId = event.body?.action?.data?.list?.id; - return await this.trello.getList(listId); + return await this.app.getList({ + listId, + }); }, }, }; diff --git a/components/trello/sources/new-member-on-card/new-member-on-card.mjs b/components/trello/sources/new-member-on-card/new-member-on-card.mjs index b9b71bbb680c9..a827c9beed7cf 100644 --- a/components/trello/sources/new-member-on-card/new-member-on-card.mjs +++ b/components/trello/sources/new-member-on-card/new-member-on-card.mjs @@ -5,13 +5,23 @@ export default { key: "trello-new-member-on-card", name: "New Member on Card (Instant)", description: "Emit new event for each member that join in a card.", - version: "0.0.15", + version: "0.1.0", type: "source", dedupe: "unique", methods: { ...common.methods, + getMemberCards({ + userId, ...args + } = {}) { + return this.app._makeRequest({ + path: `/members/${userId}/cards`, + ...args, + }); + }, async getSampleEvents() { - const cards = await this.trello.getMemberCards("me"); + const cards = await this.getMemberCards({ + userId: "me", + }); return { sampleEvents: cards, sortField: "dateLastActivity", @@ -23,7 +33,9 @@ export default { }, async getResult(event) { const cardId = event.body?.action?.data?.card?.id; - return this.trello.getCard(cardId); + return this.app.getCard({ + cardId, + }); }, generateMeta({ id, name: summary, dateLastActivity, diff --git a/components/trello/sources/new-notification/new-notification.mjs b/components/trello/sources/new-notification/new-notification.mjs index d76f51da2757f..ed1b48046b627 100644 --- a/components/trello/sources/new-notification/new-notification.mjs +++ b/components/trello/sources/new-notification/new-notification.mjs @@ -6,11 +6,19 @@ export default { name: "New Notification", description: "Emit new event for each new Trello notification for the authenticated user.", - version: "0.0.11", + version: "0.1.0", type: "source", dedupe: "unique", methods: { ...common.methods, + getNotifications({ + notificationId, ...args + } = {}) { + return this.app._makeRequest({ + path: `/members/${notificationId}/notifications`, + ...args, + }); + }, _getLastNotificationId() { return this.db.get("lastNotificationId") || null; }, @@ -29,11 +37,13 @@ export default { }, async run() { const since = this._getLastNotificationId(); - const params = { - since, - }; - const notifications = await this.trello.getNotifications("me", params); + const notifications = await this.getNotifications({ + notificationId: "me", + params: { + since, + }, + }); const { length: notificationCount = 0 } = notifications; if (notificationCount <= 0) { diff --git a/components/trello/trello.app.mjs b/components/trello/trello.app.mjs index 8a843696e3331..bada2c9547882 100644 --- a/components/trello/trello.app.mjs +++ b/components/trello/trello.app.mjs @@ -1,37 +1,40 @@ import { axios } from "@pipedream/platform"; -import crypto from "crypto"; -import events from "./common/events.mjs"; import fields from "./common/fields.mjs"; -import mime from "mime"; export default { type: "app", app: "trello", description: "Pipedream Trello Components", propDefinitions: { - cards: { - type: "string[]", - label: "Cards", - description: "The Trello cards you wish to select", - optional: true, - async options(opts) { - const cards = await this.getCards(opts.board); - return cards.map((card) => ({ - label: card.name, - value: card.id, - })); - }, - }, board: { type: "string", label: "Board", description: "The Trello board you wish to select", async options() { const boards = await this.getBoards(); - const activeBoards = boards.filter((board) => board.closed === false); - return activeBoards.map((board) => ({ - label: board.name, - value: board.id, + return boards.filter(({ closed }) => closed === false) + .map(({ + id: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + cards: { + type: "string[]", + label: "Cards", + description: "The Trello cards you wish to select", + optional: true, + async options({ board }) { + const cards = await this.getCards({ + boardId: board, + }); + return cards.map(({ + id: value, name: label, + }) => ({ + label, + value, })); }, }, @@ -54,20 +57,15 @@ export default { "all", ], }, - eventTypes: { - type: "string[]", - label: "Event Types", - optional: true, - description: "Only emit events for the selected event types (e.g., `updateCard`).", - options: events, - }, lists: { type: "string[]", label: "Lists", description: "The Trello lists you wish to select", optional: true, - async options(opts) { - const lists = await this.getLists(opts.board); + async options({ board }) { + const lists = await this.getLists({ + boardId: board, + }); return lists.map((list) => ({ label: list.name, value: list.id, @@ -84,9 +82,14 @@ export default { label: "Organization IDs", description: "Specify the organizations to search for boards in", async options() { - const orgs = await this.listOrganizations(this.$auth.oauth_uid); + const orgs = await this.listOrganizations({ + memberId: this.$auth.oauth_uid, + params: { + fields: "all", + }, + }); return orgs.map((org) => ({ - label: org.name || org.id, + label: org.displayName ?? org.name ?? org.id, value: org.id, })); }, @@ -108,11 +111,15 @@ export default { type: "string", label: "Label", description: "The ID of the Label to be added to the card", - async options(opts) { - const labels = await this.findLabel(opts.board); - return labels.map((label) => ({ - label: label.name, - value: label.id, + async options({ board }) { + const labels = await this.findLabel({ + boardId: board, + }); + return labels.map(({ + name, color, id: value, + }) => ({ + label: name || color, + value, })); }, }, @@ -121,7 +128,9 @@ export default { label: "Member", description: "The ID of the Member to be added to the card", async options(opts) { - const members = await this.listMembers(opts.board); + const members = await this.listMembers({ + boardId: opts.board, + }); return members.map((member) => ({ label: member.fullName, value: member.id, @@ -132,14 +141,16 @@ export default { type: "string", label: "Checklist", description: "The ID of a checklist to copy into the new checklist", - async options(opts) { - const { - board, - card, - } = opts; + async options({ + board, card, + }) { const checklists = card ? - await this.listCardChecklists(card) : - await this.listBoardChecklists(board); + await this.listCardChecklists({ + cardId: card, + }) : + await this.listBoardChecklists({ + boardId: board, + }); return checklists.map((checklist) => ({ label: checklist.name, value: checklist.id, @@ -152,7 +163,9 @@ export default { description: "An array of custom field Ids to create/update", optional: true, async options({ boardId }) { - const customFields = await this.listCustomFields(boardId); + const customFields = await this.listCustomFields({ + boardId, + }); return customFields?.map(({ id: value, name: label, }) => ({ @@ -161,15 +174,6 @@ export default { })) || []; }, }, - mimeType: { - type: "string", - label: "File Attachment Type", - description: "Not required for URL attachment", - optional: true, - options() { - return Object.values(mime._types); - }, - }, name: { type: "string", label: "Name", @@ -180,6 +184,19 @@ export default { type: "string", label: "File Attachment URL", description: "URL must start with `http://` or `https://`", + optional: true, + }, + mimeType: { + type: "string", + label: "File Attachment Type", + description: "Not required for **File Attachment URL** property. Eg. `application/pdf`", + optional: true, + }, + file: { + type: "string", + label: "File Attachment Path", + description: "The path to the file saved to the `/tmp` directory (e.g. `/tmp/example.pdf`). [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory). If you provide a file path, the **File Attachment URL** field will be ignored.", + optional: true, }, desc: { type: "string", @@ -259,422 +276,203 @@ export default { default: false, optional: true, }, + checklistItemId: { + type: "string", + label: "Checklist Item ID", + description: "The ID of the checklist item.", + async options({ checklistId }) { + const checkItems = await this.listCheckItems({ + checklistId, + }); + return checkItems.map(({ + name: label, id: value, + }) => ({ + label, + value, + })); + }, + }, + cardAttachmentId: { + type: "string", + label: "Cover Attachment ID", + description: "Assign an attachment id to be the cover image for the card", + optional: true, + async options({ + cardId, params, + }) { + const attachments = await this.listCardAttachments({ + cardId, + params, + }); + return attachments.map(({ + name, url, id: value, + }) => ({ + label: name || url, + value, + })); + }, + }, }, methods: { - _getBaseUrl() { - return "https://api.trello.com/1/"; - }, - async _getAuthorizationHeader({ - data, method, url, - }, $) { - const requestData = { - data, - method, - url, - }; - const token = { - key: this.$auth.oauth_access_token, - secret: this.$auth.oauth_refresh_token, - }; - return axios($ ?? this, { - method: "POST", - url: this.$auth.oauth_signer_uri, - data: { - requestData, - token, - }, - }); + getSignerUri() { + return this.$auth.oauth_signer_uri; }, - async _makeRequest(args, $) { + getToken() { const { - method = "GET", - path, - ...otherArgs - } = args; - const config = { - method, - url: `${this._getBaseUrl()}${path}`, - ...otherArgs, - }; - const authorization = await this._getAuthorizationHeader(config, $); - config.headers = { - ...config.headers, - authorization, - }; - try { - return await axios($ ?? this, config); - } catch (err) { - console.log(err); - } - }, - /** - * Archives a card. - * - * @param {string} idCard - the ID of the Card to archive. - * @returns an updated card object with `closed` (archived) property set to true. - * See more at the API docs: - * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put - */ - async archiveCard(idCard, $) { - const config = { - path: `cards/${idCard}`, - method: "PUT", - data: { - closed: true, - }, - }; - return this._makeRequest(config, $); - }, - /** - * Create an Attachment to a Card - * - * @param {string} idCard - the ID of the Card to move. - * @param {Object} params - an object containing parameters for the API request - * @returns {array} an string array with the ID of all the Card's Attachments. - * See more at the API docs: - * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-attachments-post - */ - async addAttachmentToCardViaUrl(idCard, params, $) { - const config = { - path: `cards/${idCard}/attachments`, - method: "POST", - params, - }; - return this._makeRequest(config, $); - }, - /** - * Adds an existing label to the specified card. - * - * @param {string} idCard - the ID of the Card to move. - * @param {Object} params - an object containing parameters for the API request - * @returns {array} an string array with the ID of all the Card's Labels. - * See more at the API docs: - * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idlabels-post - */ - async addExistingLabelToCard(idCard, params, $) { - const config = { - path: `cards/${idCard}/idLabels`, - method: "POST", - params, - }; - return this._makeRequest(config, $); - }, - /** - * Add a member to a card - * - * @param {string} idCard - the ID of the Card to move. - * @param {Object} params - an object containing parameters for the API request - * @returns {array} an string array with the ID of all the Card's Members. - * See more at the API docs: - * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idmembers-post - */ - async addMemberToCard(idCard, params, $) { - const config = { - path: `cards/${idCard}/idMembers`, - method: "POST", - params, - }; - return this._makeRequest(config, $); - }, - /** - * Creates a checklist on the specified card. - * - * @param {Object} params - an object containing parameters for the API request - * @returns an object with the created checklist. - * See more at the API docs: - * https://developer.atlassian.com/cloud/trello/rest/api-group-checklists/#api-checklists-post - */ - async createChecklist(params, $) { - const config = { - path: "checklists", - method: "POST", - params, - }; - return this._makeRequest(config, $); - }, - /** - * Creates a comment on a card. - * - * @param {string} idCard - the ID of the Card that the comment should be created on. - * @param {Object} params - an object containing parameters for the API request - * @returns a object containing a summary of the related card, members, and other Trello - * entities related to the newly created comment. - * See more at the API docs: - * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-actions-comments-post - */ - async createCommentOnCard(idCard, comment, $) { - const config = { - path: `cards/${idCard}/actions/comments`, - method: "POST", - params: { - text: comment, - }, - }; - return this._makeRequest(config, $); - }, - /** - * Closes a board. - * - * @param {string} boardId - the ID of the Board to close. - * @returns the updated board object with the `closed` property set to true. - * See more at the API docs: - * https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-put - */ - async closeBoard(boardId, $) { - const config = { - path: `boards/${boardId}`, - method: "PUT", - data: { - closed: true, - }, + oauth_access_token: key, + oauth_refresh_token: secret, + } = this.$auth; + return { + key, + secret, }; - return this._makeRequest(config, $); }, - /** - * Creates a new card. - * - * @param {Object} opts - an object containing data for the API request - * @returns the created card object. See more at the API docs: - * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-post - */ - async createCard(opts, $) { - const config = { - path: "cards", - method: "post", - data: opts, - }; - return this._makeRequest(config, $); - }, - /** - * Deletes the specified checklist. - * - * @param {string} idChecklist - the ID of the checklist to delete. - * @returns {object} an empty `limits` object indicating the operation completed successfully. - */ - async deleteChecklist(idChecklist, $) { - const config = { - path: `checklists/${idChecklist}`, - method: "DELETE", - }; - return this._makeRequest(config, $); - }, - /** - * Finds a label on a specific board. - * - * @param {string} boardId - unique identifier of the board to search for labels. - * @param {Object} params - an object containing parameters for the API request - * @returns {array} an array with label objects complying with the specified parameters. - */ - async findLabel(boardId, params, $) { - const config = { - path: `boards/${boardId}/labels`, - params, - }; - return this._makeRequest(config, $); + getUrl(path) { + return `https://api.trello.com/1${path}`; }, - /** - * Finds a list in the specified board. - * - * @param {string} - boardId unique identifier of the board to search for lists. - * @param {Object} params - an object containing parameters for the API request - * @returns {array} an array with list objects conforming with the specified parameters. - */ - async findList(boardId, params, $) { - const config = { - path: `boards/${boardId}/lists`, - params, + _makeRequest({ + $ = this, path, ...args + } = {}) { + const signConfig = { + token: this.getToken(), + oauthSignerUri: this.getSignerUri(), }; - return this._makeRequest(config, $); - }, - /** - * Moves a card to the specified board/list pair. - * - * @param {string} idCard the ID of the Card to move. - * @param {Object} data - an object containing data for the API request - * @returns an updated card object set to the specified board and list ids. - * See more at the API docs: - * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put - */ - async moveCardToList(idCard, data, $) { + const config = { - path: `cards/${idCard}`, - method: "PUT", - data, - }; - return this._makeRequest(config, $); - }, - async verifyTrelloWebhookRequest(request, callbackURL) { - let secret = this.$auth.oauth_refresh_token; - const base64Digest = function (s) { - return crypto.createHmac("sha1", secret).update(s) - .digest("base64"); + ...args, + url: this.getUrl(path), }; - const content = JSON.stringify(request.body) + callbackURL; - const doubleHash = base64Digest(content); - const headerHash = request.headers["x-trello-webhook"]; - return doubleHash === headerHash; + + return axios($, config, signConfig); }, - async getBoardActivity(boardId, filter = null) { + post(args = {}) { return this._makeRequest({ - path: `boards/${boardId}/actions`, - params: { - filter, - }, + method: "POST", + ...args, }); }, - async getCardActivity(cardId, filter = null) { + put(args = {}) { return this._makeRequest({ - path: `cards/${cardId}/actions`, - params: { - filter, - }, + method: "PUT", + ...args, }); }, - async getBoard(id) { + delete(args = {}) { return this._makeRequest({ - path: `boards/${id}`, + method: "DELETE", + ...args, }); }, - async getBoards(id = this.$auth.oauth_uid) { - return this._makeRequest({ - path: `members/${id}/boards`, + createBoard(args = {}) { + return this.post({ + path: "/boards", + ...args, }); }, - /** - * Gets details of a card. - * - * @param {string} id - the ID of the card to get details of. - * @returns {object} a card object. See more at the API docs: - * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-post - */ - async getCard(id, params = {}, $) { - return this._makeRequest({ - path: `cards/${id}`, - params, - }, $); - }, - async getCards(id, params = {}, $) { - return this._makeRequest({ - path: `boards/${id}/cards`, - params, - }, $); - }, - async getFilteredCards(boardId, filter) { - return this._makeRequest({ - path: `boards/${boardId}/cards`, - params: { - filter, - }, + updateBoard({ + boardId, ...args + } = {}) { + return this.put({ + path: `/boards/${boardId}`, + ...args, }); }, - async getCardsInList(listId, params = {}, $) { - return this._makeRequest({ - path: `lists/${listId}/cards`, - params, - }, $); + updateCard({ + cardId, ...args + } = {}) { + return this.put({ + path: `/cards/${cardId}`, + ...args, + }); }, - async getMemberCards(userId) { + findLabel({ + boardId, ...args + } = {}) { return this._makeRequest({ - path: `members/${userId}/cards`, + path: `/boards/${boardId}/labels`, + ...args, }); }, - async getChecklist(id) { + getBoardActivity({ + boardId, ...args + } = {}) { return this._makeRequest({ - path: `checklists/${id}`, + path: `/boards/${boardId}/actions`, + ...args, }); }, - async getLabel(id) { + getBoard({ + boardId, ...args + } = {}) { return this._makeRequest({ - path: `labels/${id}`, + path: `/boards/${boardId}`, + ...args, }); }, - async getList(id) { + getBoards({ + boardId = this.$auth.oauth_uid, ...args + } = {}) { return this._makeRequest({ - path: `lists/${id}`, + path: `/members/${boardId}/boards`, + ...args, }); }, - async getLists(id) { + getCard({ + cardId, ...args + } = {}) { return this._makeRequest({ - path: `boards/${id}/lists`, + path: `/cards/${cardId}`, + ...args, }); }, - async getNotifications(id, params) { + getCards({ + boardId, ...args + } = {}) { return this._makeRequest({ - path: `members/${id}/notifications`, - params, + path: `/boards/${boardId}/cards`, + ...args, }); }, - async getMember(id) { + getCardsInList({ + listId, ...args + } = {}) { return this._makeRequest({ - path: `members/${id}`, + path: `/lists/${listId}/cards`, + ...args, }); }, - async getAttachment(cardId, attachmentId) { + getLabel({ + labelId, ...args + } = {}) { return this._makeRequest({ - path: `cards/${cardId}/attachments/${attachmentId}`, + path: `/labels/${labelId}`, + ...args, }); }, - async getCardList(cardId) { + getLists({ + boardId, ...args + } = {}) { return this._makeRequest({ - path: `cards/${cardId}/list`, + path: `/boards/${boardId}/lists`, + ...args, }); }, - async createHook({ - id, endpoint, - }) { - const resp = await this._makeRequest({ - method: "post", - path: "webhooks/", - headers: { - "Content-Type": "applicaton/json", - }, - params: { - idModel: id, - description: "Pipedream Source ID", //todo add ID - callbackURL: endpoint, - }, + getList({ + listId, ...args + } = {}) { + return this._makeRequest({ + path: `/lists/${listId}`, + ...args, }); - return resp; }, - async deleteHook({ hookId }) { + getMember({ + memberId, ...args + } = {}) { return this._makeRequest({ - method: "delete", - path: `webhooks/${hookId}`, + path: `/members/${memberId}`, + ...args, }); }, - /** - * Removes an existing label from the specified card. - * - * @param {string} idCard - the ID of the Card to remove the Label from. - * @param {string} idLabel - the ID of the Label to be removed from the card. - * @returns {object} an object with the null valued property `_value` indicating that - * there were no errors - */ - async removeLabelFromCard(idCard, idLabel, $) { - const config = { - path: `cards/${idCard}/idLabels/${idLabel}`, - method: "DELETE", - }; - return this._makeRequest(config, $); - }, - /** - * Renames the specified list - * - * @param {string} listId - the ID of the List to rename. - * @param {Object} data - an object containing data for the API request - * @returns {object} a list object with the `closed` property, indicated if the list is - * closed or archived, `id` the id of the renamed List, `idBoard` the id of the Board parent - * to the List, `name` with the new name of the List, and `pos` with the position of the List - * in the Board. - */ - async renameList(listId, data, $) { - const config = { - path: `lists/${listId}`, - method: "PUT", - data, - }; - return this._makeRequest(config, $); - }, /** * Searches for members, cards, boards, and/or organizations matching the specified query. * @@ -684,99 +482,83 @@ export default { * this case "cards"), `partial` the search `terms` as included in `query`, and other * `modifiers`. */ - async search(params, $) { - const config = { - path: "search", - params, - }; - return this._makeRequest(config, $); - }, - /** - * Searches for boards matching the specified query. - * - * @param {Object} opts - an object containing data for the API request - * @returns {cards: array, options: object} an array with the `cards` objects matching the - * specified `query`, and an object with the `options` for the search, such as `modelTypes` (in - * this case "cards"), `partial` the search `terms` as included in `query`, and other - * `modifiers`. - */ - async searchBoards(opts, $) { - const params = { - ...opts, - idOrganizations: opts.idOrganizations?.join(","), - }; - return this.search(params, $); - }, - /** - * Searches for cards matching the specified query. - * - * @param {Object} opts - an object containing data for the API request - * @returns {cards: array, options: object} an array with the `cards` objects matching the - * specified `query`, and an object with the `options` for the search, such as `modelTypes` (in - * this case "cards"), `partial` the search `terms` as included in `query`, and other - * `modifiers`. - */ - async searchCards(opts, $) { - const params = { - ...opts, - idOrganizations: opts.idOrganizations?.join(","), - idCards: opts.idCards?.join(","), - }; - return this.search(params, $); + search(args = {}) { + return this._makeRequest({ + path: "/search", + ...args, + }); }, - /** - * Updates a card. - * - * @param {string} idCard - the ID of the card to update - * @param {Object} params - an object containing parameters for the API request - * @returns the updated card object. See more at the API docs: - * https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-post - */ - async updateCard(idCard, - params, $) { - const config = { - path: `cards/${idCard}`, - method: "PUT", - params, - }; - return this._makeRequest(config, $); + listMembers({ + boardId, ...args + } = {}) { + return this._makeRequest({ + path: `/boards/${boardId}/members`, + ...args, + }); }, - async listMembers(board) { + listBoardChecklists({ + boardId, ...args + } = {}) { return this._makeRequest({ - path: `boards/${board}/members`, + path: `/boards/${boardId}/checklists`, + ...args, }); }, - async listBoardChecklists(board) { + listCardChecklists({ + cardId, ...args + } = {}) { return this._makeRequest({ - path: `boards/${board}/checklists`, + path: `/cards/${cardId}/checklists`, + ...args, }); }, - async listCardChecklists(card) { + listOrganizations({ + memberId, ...args + } = {}) { return this._makeRequest({ - path: `cards/${card}/checklists`, + path: `/members/${memberId}/organizations`, + ...args, }); }, - async listOrganizations(id) { + getCustomField({ + customFieldId, ...args + } = {}) { return this._makeRequest({ - path: `members/${id}/organizations?fields="id,name"`, + path: `/customFields/${customFieldId}`, + ...args, }); }, - getCustomField(customFieldId, $) { + listCustomFields({ + boardId, ...args + } = {}) { return this._makeRequest({ - path: `customFields/${customFieldId}`, - }, $); + path: `/boards/${boardId}/customFields`, + ...args, + }); + }, + updateCustomFields({ + cardId, ...args + } = {}) { + return this.put({ + path: `/cards/${cardId}/customFields`, + ...args, + }); }, - listCustomFields(boardId, $) { + listCheckItems({ + checklistId, ...args + } = {}) { return this._makeRequest({ - path: `boards/${boardId}/customFields`, - }, $); + path: `/checklists/${checklistId}/checkItems`, + ...args, + }); }, - updateCustomFields(cardId, data, $) { + listCardAttachments({ + cardId, ...args + } = {}) { return this._makeRequest({ - method: "PUT", - path: `cards/${cardId}/customFields`, - data, - }, $); + path: `/cards/${cardId}/attachments`, + ...args, + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 64e0e710fe76d..f304d2a120b48 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10119,15 +10119,17 @@ importers: components/trello: specifiers: - '@pipedream/platform': ^1.5.1 + '@pipedream/platform': ^3.0.1 crypto: ^1.0.1 + form-data: ^4.0.0 lodash-es: ^4.17.21 - mime: ^3.0.0 + ms: ^2.1.3 dependencies: - '@pipedream/platform': 1.5.1 + '@pipedream/platform': 3.0.1 crypto: 1.0.1 + form-data: 4.0.0 lodash-es: 4.17.21 - mime: 3.0.0 + ms: 2.1.3 components/trengo: specifiers: