From 75f7d61758dd31ef92b46dfcf77766079c6dc5f9 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 3 Dec 2024 13:45:01 -0300 Subject: [PATCH 1/8] [ACTION] Sendgrid "Campaign sends" #14026 Actions - Create Send --- .../add-email-to-global-suppression.mjs | 2 +- .../add-or-update-contact.mjs | 2 +- .../create-contact-list.mjs | 2 +- .../actions/create-send/create-send.mjs | 159 ++++++++++++++++++ .../actions/delete-blocks/delete-blocks.mjs | 2 +- .../actions/delete-bounces/delete-bounces.mjs | 2 +- .../delete-contacts/delete-contacts.mjs | 2 +- .../delete-global-suppression.mjs | 2 +- .../actions/delete-list/delete-list.mjs | 2 +- .../actions/get-a-block/get-a-block.mjs | 2 +- .../get-a-global-suppression.mjs | 2 +- .../get-all-bounces/get-all-bounces.mjs | 2 +- .../get-contact-lists/get-contact-lists.mjs | 2 +- .../actions/list-blocks/list-blocks.mjs | 2 +- .../list-global-suppressions.mjs | 2 +- .../remove-contact-from-list.mjs | 2 +- .../search-contacts/search-contacts.mjs | 4 +- .../send-email-multiple-recipients.mjs | 2 +- .../send-email-single-recipient.mjs | 2 +- .../actions/validate-email/validate-email.mjs | 2 +- components/sendgrid/common/constants.mjs | 1 + components/sendgrid/common/utils.mjs | 24 +++ components/sendgrid/package.json | 4 +- components/sendgrid/sendgrid.app.mjs | 115 ++++++++++++- components/sendgrid/sources/events/events.mjs | 2 +- .../sources/new-contact/new-contact.mjs | 2 +- 26 files changed, 319 insertions(+), 28 deletions(-) create mode 100644 components/sendgrid/actions/create-send/create-send.mjs create mode 100644 components/sendgrid/common/constants.mjs create mode 100644 components/sendgrid/common/utils.mjs diff --git a/components/sendgrid/actions/add-email-to-global-suppression/add-email-to-global-suppression.mjs b/components/sendgrid/actions/add-email-to-global-suppression/add-email-to-global-suppression.mjs index ad996d468dc67..70d9071ab09c3 100644 --- a/components/sendgrid/actions/add-email-to-global-suppression/add-email-to-global-suppression.mjs +++ b/components/sendgrid/actions/add-email-to-global-suppression/add-email-to-global-suppression.mjs @@ -5,7 +5,7 @@ export default { key: "sendgrid-add-email-to-global-suppression", name: "Add Email to Global Suppression", description: "Allows you to add one or more email addresses to the global suppressions group. [See the docs here](https://sendgrid.api-docs.io/v3.0/suppressions-global-suppressions/add-recipient-addresses-to-the-global-suppression-group)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/add-or-update-contact/add-or-update-contact.mjs b/components/sendgrid/actions/add-or-update-contact/add-or-update-contact.mjs index 95feea7824c13..6050fdfdcad74 100644 --- a/components/sendgrid/actions/add-or-update-contact/add-or-update-contact.mjs +++ b/components/sendgrid/actions/add-or-update-contact/add-or-update-contact.mjs @@ -6,7 +6,7 @@ export default { key: "sendgrid-add-or-update-contact", name: "Add or Update Contact", description: "Adds or updates a contact. [See the docs here](https://docs.sendgrid.com/api-reference/contacts/add-or-update-a-contact)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/create-contact-list/create-contact-list.mjs b/components/sendgrid/actions/create-contact-list/create-contact-list.mjs index fda8dc134dd99..4a9492e4955cb 100644 --- a/components/sendgrid/actions/create-contact-list/create-contact-list.mjs +++ b/components/sendgrid/actions/create-contact-list/create-contact-list.mjs @@ -5,7 +5,7 @@ export default { key: "sendgrid-create-contact-list", name: "Create Contact List", description: "Allows you to create a new contact list. [See the docs here](https://docs.sendgrid.com/api-reference/lists/create-list)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/create-send/create-send.mjs b/components/sendgrid/actions/create-send/create-send.mjs new file mode 100644 index 0000000000000..8d32825640536 --- /dev/null +++ b/components/sendgrid/actions/create-send/create-send.mjs @@ -0,0 +1,159 @@ +import { ConfigurationError } from "@pipedream/platform"; +import { parseObject } from "../../common/utils.mjs"; +import common from "../common/common.mjs"; + +export default { + ...common, + key: "sendgrid-create-send", + name: "Create Send", + description: "Create a single send. [See the docs here](https://www.twilio.com/docs/sendgrid/api-reference/single-sends/create-single-send)", + version: "0.0.1", + type: "action", + props: { + ...common.props, + name: { + type: "string", + label: "Name", + description: "The name of the Single Send.", + }, + categoryIds: { + propDefinition: [ + common.props.sendgrid, + "categoryIds", + ], + optional: true, + }, + sendAt: { + type: "string", + label: "Send At", + description: "Set this property to an ISO 8601 formatted date-time (YYYY-MM-DDTHH:MM:SSZ) when you would like to send the Single Send. Please note that any `send_at` property value set with this endpoint will prepopulate the send date in the SendGrid user interface (UI). However, the Single Send will remain an unscheduled draft until it's updated with the [Schedule Single Send](https://www.twilio.com/docs/sendgrid/api-reference/single-sends/schedule-single-send) endpoint or SendGrid application UI. Setting this property to `now` with this endpoint will cause an error.", + optional: true, + }, + listIds: { + propDefinition: [ + common.props.sendgrid, + "listIds", + ], + description: "The recipient List IDs that will receive the Single Send.", + optional: true, + }, + segmentIds: { + propDefinition: [ + common.props.sendgrid, + "segmentIds", + ], + optional: true, + }, + all: { + type: "boolean", + label: "All", + description: "Set to `true` to send to All Contacts. If set to `false`, at least one `List Ids` or `Segment Ids` value must be provided before the Single Send is scheduled to be sent to recipients.", + optional: true, + }, + subject: { + type: "string", + label: "Subject", + description: "The subject line of the Single Send. Do not include this field when using a `Design Id`.", + optional: true, + }, + htmlContent: { + type: "string", + label: "HTML Content", + description: "The HTML content of the Single Send. Do not include this field when using a `Design Id`.", + optional: true, + }, + plainContent: { + type: "string", + label: "Plain Content", + description: "The plain text content of the Single Send. Do not include this field when using a `Design Id`.", + optional: true, + }, + generatePlainContent: { + type: "boolean", + label: "Generate Plain Content", + description: "If set to `true`, `Plain Content` is always generated from `HTML Content`. If set to false, `Plain Content` is not altered.", + optional: true, + }, + designId: { + propDefinition: [ + common.props.sendgrid, + "designId", + ], + optional: true, + }, + editor: { + type: "string", + label: "Editor", + description: "The editor is used to modify the Single Send's design in the Marketing Campaigns App.", + options: [ + "design", + "code", + ], + optional: true, + }, + suppressionGroupId: { + type: "integer", + label: "Suppression Group Id", + description: "The ID of the Suppression Group to allow recipients to unsubscribe — you must provide this or the `Custom Unsubscribe URL`.", + optional: true, + }, + customUnsubscribeUrl: { + type: "string", + label: "Custom Unsubscribe URL", + description: "The URL allowing recipients to unsubscribe — you must provide this or the `Suppression Group Id`.", + optional: true, + }, + senderId: { + propDefinition: [ + common.props.sendgrid, + "senderId", + ], + optional: true, + }, + ipPool: { + type: "string", + label: "IP Pool", + description: "The name of the IP Pool from which the Single Send emails are sent.", + optional: true, + }, + }, + async run({ $ }) { + if (!this.suppressionGroupId && !this.customUnsubscribeUrl) { + throw new ConfigurationError("You must provide either `Suppression Goup Id` or the `Custom Unsubscribe URL`."); + } + try { + const resp = await this.sendgrid.createSingleSend({ + $, + data: { + name: this.name, + categories: parseObject(this.categories), + send_at: this.sendAt, + send_to: { + list_ids: parseObject(this.listIds), + segment_ids: parseObject(this.segmentIds), + all: this.all, + }, + email_config: { + subject: this.subject, + html_content: this.htmlContent, + plain_content: this.plainContent, + generate_plain_content: this.generatePlainContent, + design_id: this.designId, + editor: this.editor, + suppression_group_id: this.suppressionGroupId, + custom_unsubscribe_url: this.customUnsubscribeUrl, + sender_id: this.senderId, + ip_pool: this.ipPool, + }, + }, + }); + $.export("$summary", `Successfully created contact ${this.name}`); + return resp; + } catch (e) { + const errors = e.split("Unexpected error (status code: ERR_BAD_REQUEST):")[1]; + const errorJson = JSON.parse(errors); + + throw new ConfigurationError(errorJson.data.errors[0].message); + } + }, +}; diff --git a/components/sendgrid/actions/delete-blocks/delete-blocks.mjs b/components/sendgrid/actions/delete-blocks/delete-blocks.mjs index d21a502796b21..bc1134e950786 100644 --- a/components/sendgrid/actions/delete-blocks/delete-blocks.mjs +++ b/components/sendgrid/actions/delete-blocks/delete-blocks.mjs @@ -5,7 +5,7 @@ export default { key: "sendgrid-delete-blocks", name: "Delete Blocks", description: "Allows you to delete all email addresses on your blocks list. [See the docs here](https://docs.sendgrid.com/api-reference/blocks-api/delete-blocks)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/delete-bounces/delete-bounces.mjs b/components/sendgrid/actions/delete-bounces/delete-bounces.mjs index 106a774bff4d8..d04c0d91d6631 100644 --- a/components/sendgrid/actions/delete-bounces/delete-bounces.mjs +++ b/components/sendgrid/actions/delete-bounces/delete-bounces.mjs @@ -5,7 +5,7 @@ export default { key: "sendgrid-delete-bounces", name: "Delete Bounces", description: "Allows you to delete all emails on your bounces list. [See the docs here](https://docs.sendgrid.com/api-reference/bounces-api/delete-bounces)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/delete-contacts/delete-contacts.mjs b/components/sendgrid/actions/delete-contacts/delete-contacts.mjs index af1193c00757b..630f73000c3fc 100644 --- a/components/sendgrid/actions/delete-contacts/delete-contacts.mjs +++ b/components/sendgrid/actions/delete-contacts/delete-contacts.mjs @@ -5,7 +5,7 @@ export default { key: "sendgrid-delete-contacts", name: "Delete Contacts", description: "Allows you to delete one or more contacts. [See the docs here](https://docs.sendgrid.com/api-reference/contacts/delete-contacts)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/delete-global-suppression/delete-global-suppression.mjs b/components/sendgrid/actions/delete-global-suppression/delete-global-suppression.mjs index e8229e8022ad2..a854cec3c5056 100644 --- a/components/sendgrid/actions/delete-global-suppression/delete-global-suppression.mjs +++ b/components/sendgrid/actions/delete-global-suppression/delete-global-suppression.mjs @@ -6,7 +6,7 @@ export default { key: "sendgrid-delete-global-suppression", name: "Delete Global Suppression", description: "Allows you to remove an email address from the global suppressions group. [See the docs here](https://docs.sendgrid.com/api-reference/suppressions-global-suppressions/delete-a-global-suppression)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/delete-list/delete-list.mjs b/components/sendgrid/actions/delete-list/delete-list.mjs index 7edcff6ad4e09..fcbf401a01dd1 100644 --- a/components/sendgrid/actions/delete-list/delete-list.mjs +++ b/components/sendgrid/actions/delete-list/delete-list.mjs @@ -5,7 +5,7 @@ export default { key: "sendgrid-delete-list", name: "Delete List", description: "Allows you to delete a specific contact list. [See the docs here](https://docs.sendgrid.com/api-reference/lists/delete-a-list)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/get-a-block/get-a-block.mjs b/components/sendgrid/actions/get-a-block/get-a-block.mjs index 24f8602441761..923276deada11 100644 --- a/components/sendgrid/actions/get-a-block/get-a-block.mjs +++ b/components/sendgrid/actions/get-a-block/get-a-block.mjs @@ -6,7 +6,7 @@ export default { key: "sendgrid-get-a-block", name: "Get a Block", description: "Gets a specific block. [See the docs here](https://docs.sendgrid.com/api-reference/blocks-api/retrieve-a-specific-block)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/get-a-global-suppression/get-a-global-suppression.mjs b/components/sendgrid/actions/get-a-global-suppression/get-a-global-suppression.mjs index e83c7c56e833c..775c795c759a9 100644 --- a/components/sendgrid/actions/get-a-global-suppression/get-a-global-suppression.mjs +++ b/components/sendgrid/actions/get-a-global-suppression/get-a-global-suppression.mjs @@ -6,7 +6,7 @@ export default { key: "sendgrid-get-a-global-suppression", name: "Get A Global Suppression", description: "Gets a global suppression. [See the docs here](https://docs.sendgrid.com/api-reference/suppressions-global-suppressions/retrieve-a-global-suppression)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/get-all-bounces/get-all-bounces.mjs b/components/sendgrid/actions/get-all-bounces/get-all-bounces.mjs index aaaee47fb9b63..5bd9a6cf4224d 100644 --- a/components/sendgrid/actions/get-all-bounces/get-all-bounces.mjs +++ b/components/sendgrid/actions/get-all-bounces/get-all-bounces.mjs @@ -6,7 +6,7 @@ export default { key: "sendgrid-get-all-bounces", name: "Get All Bounces", description: "Allows you to get all of your bounces. [See the docs here](https://docs.sendgrid.com/api-reference/bounces-api/retrieve-all-bounces)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/get-contact-lists/get-contact-lists.mjs b/components/sendgrid/actions/get-contact-lists/get-contact-lists.mjs index ace639d9db668..fe1c4d38fb4fb 100644 --- a/components/sendgrid/actions/get-contact-lists/get-contact-lists.mjs +++ b/components/sendgrid/actions/get-contact-lists/get-contact-lists.mjs @@ -5,7 +5,7 @@ export default { key: "sendgrid-get-contact-lists", name: "Get Contact Lists", description: "Allows you to get details of your contact lists. [See the docs here](https://docs.sendgrid.com/api-reference/lists/get-all-lists)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/list-blocks/list-blocks.mjs b/components/sendgrid/actions/list-blocks/list-blocks.mjs index 2b5ab9b36e3e0..d4607dc9e483a 100644 --- a/components/sendgrid/actions/list-blocks/list-blocks.mjs +++ b/components/sendgrid/actions/list-blocks/list-blocks.mjs @@ -6,7 +6,7 @@ export default { key: "sendgrid-list-blocks", name: "List Blocks", description: "Allows you to list all email addresses that are currently on your blocks list. [See the docs here](https://docs.sendgrid.com/api-reference/blocks-api/retrieve-all-blocks)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/list-global-suppressions/list-global-suppressions.mjs b/components/sendgrid/actions/list-global-suppressions/list-global-suppressions.mjs index 2b96282290053..8aa2b55933258 100644 --- a/components/sendgrid/actions/list-global-suppressions/list-global-suppressions.mjs +++ b/components/sendgrid/actions/list-global-suppressions/list-global-suppressions.mjs @@ -6,7 +6,7 @@ export default { key: "sendgrid-list-global-suppressions", name: "List Global Suppressions", description: "Allows you to get a list of all email address that are globally suppressed. [See the docs here](https://docs.sendgrid.com/api-reference/suppressions-global-suppressions/retrieve-all-global-suppressions)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/remove-contact-from-list/remove-contact-from-list.mjs b/components/sendgrid/actions/remove-contact-from-list/remove-contact-from-list.mjs index 975f01f99ef79..52621eabb57a8 100644 --- a/components/sendgrid/actions/remove-contact-from-list/remove-contact-from-list.mjs +++ b/components/sendgrid/actions/remove-contact-from-list/remove-contact-from-list.mjs @@ -5,7 +5,7 @@ export default { key: "sendgrid-remove-contact-from-list", name: "Remove Contact From List", description: "Allows you to remove contacts from a given list. [See the docs here](https://docs.sendgrid.com/api-reference/lists/remove-contacts-from-a-list)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/search-contacts/search-contacts.mjs b/components/sendgrid/actions/search-contacts/search-contacts.mjs index a4211590e5468..b0feca6388420 100644 --- a/components/sendgrid/actions/search-contacts/search-contacts.mjs +++ b/components/sendgrid/actions/search-contacts/search-contacts.mjs @@ -1,13 +1,13 @@ +import { ConfigurationError } from "@pipedream/platform"; import common from "../common/common.mjs"; import constants from "../common/constants.mjs"; -import { ConfigurationError } from "@pipedream/platform"; export default { ...common, key: "sendgrid-search-contacts", name: "Search Contacts", description: "Searches contacts with a SGQL query. [See the docs here](https://docs.sendgrid.com/api-reference/contacts/search-contacts)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/send-email-multiple-recipients/send-email-multiple-recipients.mjs b/components/sendgrid/actions/send-email-multiple-recipients/send-email-multiple-recipients.mjs index 18bb9009b0b19..a2a1f23ea035b 100644 --- a/components/sendgrid/actions/send-email-multiple-recipients/send-email-multiple-recipients.mjs +++ b/components/sendgrid/actions/send-email-multiple-recipients/send-email-multiple-recipients.mjs @@ -6,7 +6,7 @@ export default { key: "sendgrid-send-email-multiple-recipients", name: "Send Email Multiple Recipients", description: "This action sends a personalized e-mail to multiple specified recipients. [See the docs here](https://docs.sendgrid.com/api-reference/mail-send/mail-send)", - version: "0.0.4", + version: "0.0.5", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/send-email-single-recipient/send-email-single-recipient.mjs b/components/sendgrid/actions/send-email-single-recipient/send-email-single-recipient.mjs index 2eefa5cebff61..1514ce68d1b8d 100644 --- a/components/sendgrid/actions/send-email-single-recipient/send-email-single-recipient.mjs +++ b/components/sendgrid/actions/send-email-single-recipient/send-email-single-recipient.mjs @@ -6,7 +6,7 @@ export default { key: "sendgrid-send-email-single-recipient", name: "Send Email Single Recipient", description: "This action sends a personalized e-mail to the specified recipient. [See the docs here](https://docs.sendgrid.com/api-reference/mail-send/mail-send)", - version: "0.0.6", + version: "0.0.7", type: "action", props: { ...common.props, diff --git a/components/sendgrid/actions/validate-email/validate-email.mjs b/components/sendgrid/actions/validate-email/validate-email.mjs index 7aa2c703abf7c..4d1fd7b07248c 100644 --- a/components/sendgrid/actions/validate-email/validate-email.mjs +++ b/components/sendgrid/actions/validate-email/validate-email.mjs @@ -6,7 +6,7 @@ export default { key: "sendgrid-validate-email", name: "Validate Email", description: "Validates an email address. This action requires a Sendgrid's Pro or Premier plan. [See the docs here](https://docs.sendgrid.com/api-reference/e-mail-address-validation/validate-an-email)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { ...common.props, diff --git a/components/sendgrid/common/constants.mjs b/components/sendgrid/common/constants.mjs new file mode 100644 index 0000000000000..ea830c15a04cb --- /dev/null +++ b/components/sendgrid/common/constants.mjs @@ -0,0 +1 @@ +export const LIMIT = 100; diff --git a/components/sendgrid/common/utils.mjs b/components/sendgrid/common/utils.mjs new file mode 100644 index 0000000000000..dcc9cc61f6f41 --- /dev/null +++ b/components/sendgrid/common/utils.mjs @@ -0,0 +1,24 @@ +export const parseObject = (obj) => { + if (!obj) return undefined; + + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + try { + return JSON.parse(item); + } catch (e) { + return item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; diff --git a/components/sendgrid/package.json b/components/sendgrid/package.json index 93e6e8c04ac37..d09b9a5814181 100644 --- a/components/sendgrid/package.json +++ b/components/sendgrid/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/sendgrid", - "version": "0.3.10", + "version": "0.4.0", "description": "Pipedream Sendgrid Components", "main": "sendgrid.app.js", "keywords": [ @@ -10,7 +10,7 @@ "homepage": "https://pipedream.com/apps/sendgrid", "author": "Pipedream (https://pipedream.com/)", "dependencies": { - "@pipedream/platform": "^1.2.0", + "@pipedream/platform": "^3.0.3", "@sendgrid/client": "^7.6.2", "@sendgrid/eventwebhook": "^7.4.5", "async-retry": "^1.3.1", diff --git a/components/sendgrid/sendgrid.app.mjs b/components/sendgrid/sendgrid.app.mjs index 0dd7f47df80e5..49fef6ab87c7b 100644 --- a/components/sendgrid/sendgrid.app.mjs +++ b/components/sendgrid/sendgrid.app.mjs @@ -1,8 +1,10 @@ -import { axios } from "@pipedream/platform"; -import get from "lodash/get.js"; -import retry from "async-retry"; +import { + axios, ConfigurationError, +} from "@pipedream/platform"; import sendgrid from "@sendgrid/client"; -import { ConfigurationError } from "@pipedream/platform"; +import retry from "async-retry"; +import get from "lodash/get.js"; +import { LIMIT } from "./common/constants.mjs"; export default { type: "app", @@ -15,12 +17,71 @@ export default { optional: true, async options() { const lists = await this.getAllContactLists(); + console.log("lists: ", lists); + return lists.map((list) => ({ label: list.name, value: list.id, })); }, }, + segmentIds: { + type: "string[]", + label: "Segment Ids", + description: "The recipient Segment IDs that will receive the Single Send.", + optional: true, + async options() { + const { results } = await this.getAllSegments(); + return results.map(({ + id: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + designId: { + type: "string", + label: "Design Id", + description: "A design id can be used in place of `HTML Content`, `Plain Content`, and/or `Subject`.", + async options() { + const { result } = await this.getAllDesigns(); + return result.map(({ + id: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + categoryIds: { + type: "string[]", + label: "Categories", + description: "The categories to associate with this Single Send.", + async options({ page }) { + const { categories } = await this.getAllCategories({ + params: { + limit: LIMIT, + offset: LIMIT * page, + }, + }); + return categories.map((category) => category); + }, + }, + senderId: { + type: "string", + label: "Sender Id", + description: "The ID of the verified Sender.", + async options() { + const results = await this.getAllSenders(); + return results.map(({ + id: value, nickname: label, + }) => ({ + label, + value, + })); + }, + }, contactIds: { type: "string[]", label: "Contact IDs", @@ -405,6 +466,44 @@ export default { const { data } = await this._makeClientRequest(config); return data; }, + createSingleSend({ + $, ...opts + }) { + const baseUrl = this._apiUrl(); + return this._makeRequest({ + method: "POST", + headers: this._makeRequestHeader(), + url: `${baseUrl}/marketing/singlesends`, + ...opts, + }, $); + }, + getAllDesigns(opts = {}) { + const baseUrl = this._apiUrl(); + return this._makeRequest({ + headers: this._makeRequestHeader(), + url: `${baseUrl}/designs`, + ...opts, + }); + }, + getAllSenders(opts = {}) { + const baseUrl = this._apiUrl(); + return this._makeRequest({ + headers: this._makeRequestHeader(), + url: `${baseUrl}/senders`, + ...opts, + }); + }, + getAllCategories({ + $, ...opts + }) { + const baseUrl = this._apiUrl(); + return this._makeRequest({ + headers: this._makeRequestHeader(), + url: `${baseUrl}/marketing/singlesends/categories`, + ...opts, + }, $); + }, + /** * Deletes all email addresses on on the associated account blocks list * @@ -590,6 +689,14 @@ export default { } while (contactLists.length < maxItems); return contactLists.slice(0, maxItems); }, + getAllSegments(opts = {}) { + const baseUrl = this._apiUrl(); + return this._makeRequest({ + headers: this._makeRequestHeader(), + url: `${baseUrl}/marketing/segments/2.0`, + ...opts, + }); + }, /** * Lists all email addresses that are currently the associated account blocks list. * diff --git a/components/sendgrid/sources/events/events.mjs b/components/sendgrid/sources/events/events.mjs index d20baba1e3f7d..149604cee4344 100644 --- a/components/sendgrid/sources/events/events.mjs +++ b/components/sendgrid/sources/events/events.mjs @@ -7,7 +7,7 @@ export default { key: "sendgrid-events", name: "New Events (Instant)", description: "Emit new event when any of the specified SendGrid events is received", - version: "0.0.5", + version: "0.0.6", type: "source", dedupe: "unique", props: { diff --git a/components/sendgrid/sources/new-contact/new-contact.mjs b/components/sendgrid/sources/new-contact/new-contact.mjs index 2bf933feac07a..ec0a897278805 100644 --- a/components/sendgrid/sources/new-contact/new-contact.mjs +++ b/components/sendgrid/sources/new-contact/new-contact.mjs @@ -6,7 +6,7 @@ export default { key: "sendgrid-new-contact", name: "New Contact", description: "Emit new event when a new contact is created", - version: "0.0.6", + version: "0.0.7", type: "source", dedupe: "unique", hooks: { From 952f5ea8e28d9ec5a061fd9f0a6049b1b1513de2 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 3 Dec 2024 13:45:44 -0300 Subject: [PATCH 2/8] pnpm update --- pnpm-lock.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 376cb06916c1d..0bd20f0ee1d64 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8971,8 +8971,8 @@ importers: components/sendgrid: dependencies: '@pipedream/platform': - specifier: ^1.2.0 - version: 1.6.6 + specifier: ^3.0.3 + version: 3.0.3 '@sendgrid/client': specifier: ^7.6.2 version: 7.7.0 From 94be3a99a61f18c28c8852340c9780e13b63d996 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 3 Dec 2024 14:51:02 -0300 Subject: [PATCH 3/8] Update components/sendgrid/actions/create-send/create-send.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- components/sendgrid/actions/create-send/create-send.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/sendgrid/actions/create-send/create-send.mjs b/components/sendgrid/actions/create-send/create-send.mjs index 8d32825640536..7d5fd08077780 100644 --- a/components/sendgrid/actions/create-send/create-send.mjs +++ b/components/sendgrid/actions/create-send/create-send.mjs @@ -119,7 +119,7 @@ export default { }, async run({ $ }) { if (!this.suppressionGroupId && !this.customUnsubscribeUrl) { - throw new ConfigurationError("You must provide either `Suppression Goup Id` or the `Custom Unsubscribe URL`."); + throw new ConfigurationError("You must provide either `Suppression Group Id` or the `Custom Unsubscribe URL`."); } try { const resp = await this.sendgrid.createSingleSend({ From 3f86cdac1f86c440ee11f992f5d960114caa6b36 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 3 Dec 2024 14:51:17 -0300 Subject: [PATCH 4/8] Update components/sendgrid/actions/create-send/create-send.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- components/sendgrid/actions/create-send/create-send.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/sendgrid/actions/create-send/create-send.mjs b/components/sendgrid/actions/create-send/create-send.mjs index 7d5fd08077780..a3c8290b70a8d 100644 --- a/components/sendgrid/actions/create-send/create-send.mjs +++ b/components/sendgrid/actions/create-send/create-send.mjs @@ -126,7 +126,7 @@ export default { $, data: { name: this.name, - categories: parseObject(this.categories), + categories: parseObject(this.categoryIds), send_at: this.sendAt, send_to: { list_ids: parseObject(this.listIds), From 841f3373485c4a39e266e267dd5ef68a81d6d267 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 3 Dec 2024 14:51:45 -0300 Subject: [PATCH 5/8] Update components/sendgrid/actions/create-send/create-send.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- components/sendgrid/actions/create-send/create-send.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/sendgrid/actions/create-send/create-send.mjs b/components/sendgrid/actions/create-send/create-send.mjs index a3c8290b70a8d..1e7d1faccb607 100644 --- a/components/sendgrid/actions/create-send/create-send.mjs +++ b/components/sendgrid/actions/create-send/create-send.mjs @@ -147,7 +147,7 @@ export default { }, }, }); - $.export("$summary", `Successfully created contact ${this.name}`); + $.export("$summary", `Successfully created single send ${this.name}`); return resp; } catch (e) { const errors = e.split("Unexpected error (status code: ERR_BAD_REQUEST):")[1]; From ded7bb8445b9a11c03944f437393de27e327bd8b Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 3 Dec 2024 14:52:11 -0300 Subject: [PATCH 6/8] Update components/sendgrid/actions/create-send/create-send.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../sendgrid/actions/create-send/create-send.mjs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/sendgrid/actions/create-send/create-send.mjs b/components/sendgrid/actions/create-send/create-send.mjs index 1e7d1faccb607..2f6633fdfe82c 100644 --- a/components/sendgrid/actions/create-send/create-send.mjs +++ b/components/sendgrid/actions/create-send/create-send.mjs @@ -150,10 +150,12 @@ export default { $.export("$summary", `Successfully created single send ${this.name}`); return resp; } catch (e) { - const errors = e.split("Unexpected error (status code: ERR_BAD_REQUEST):")[1]; - const errorJson = JSON.parse(errors); - - throw new ConfigurationError(errorJson.data.errors[0].message); + } catch (e) { + if (e.response && e.response.data && e.response.data.errors && e.response.data.errors.length > 0) { + throw new ConfigurationError(e.response.data.errors[0].message); + } else { + throw new ConfigurationError("An unexpected error occurred."); + } } }, }; From aa0e4ce140663087138063b70a18324a596ba082 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Wed, 4 Dec 2024 13:09:51 -0300 Subject: [PATCH 7/8] fix coderabbitai commit --- components/sendgrid/actions/create-send/create-send.mjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/sendgrid/actions/create-send/create-send.mjs b/components/sendgrid/actions/create-send/create-send.mjs index 2f6633fdfe82c..09e1076407ed5 100644 --- a/components/sendgrid/actions/create-send/create-send.mjs +++ b/components/sendgrid/actions/create-send/create-send.mjs @@ -150,8 +150,12 @@ export default { $.export("$summary", `Successfully created single send ${this.name}`); return resp; } catch (e) { - } catch (e) { - if (e.response && e.response.data && e.response.data.errors && e.response.data.errors.length > 0) { + if ( + e.response + && e.response.data + && e.response.data.errors + && e.response.data.errors.length > 0 + ) { throw new ConfigurationError(e.response.data.errors[0].message); } else { throw new ConfigurationError("An unexpected error occurred."); From 871cd645ed1b5f33e83c6754bca428f1161ade5b Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Thu, 5 Dec 2024 15:52:59 -0300 Subject: [PATCH 8/8] soem adjusts --- .../actions/create-send/create-send.mjs | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/components/sendgrid/actions/create-send/create-send.mjs b/components/sendgrid/actions/create-send/create-send.mjs index 09e1076407ed5..e12d28cea8f64 100644 --- a/components/sendgrid/actions/create-send/create-send.mjs +++ b/components/sendgrid/actions/create-send/create-send.mjs @@ -36,6 +36,7 @@ export default { ], description: "The recipient List IDs that will receive the Single Send.", optional: true, + hidden: true, }, segmentIds: { propDefinition: [ @@ -43,12 +44,14 @@ export default { "segmentIds", ], optional: true, + hidden: true, }, all: { type: "boolean", label: "All", description: "Set to `true` to send to All Contacts. If set to `false`, at least one `List Ids` or `Segment Ids` value must be provided before the Single Send is scheduled to be sent to recipients.", - optional: true, + default: true, + reloadProps: true, }, subject: { type: "string", @@ -92,9 +95,10 @@ export default { optional: true, }, suppressionGroupId: { - type: "integer", - label: "Suppression Group Id", - description: "The ID of the Suppression Group to allow recipients to unsubscribe — you must provide this or the `Custom Unsubscribe URL`.", + propDefinition: [ + common.props.sendgrid, + "asmGroupId", + ], optional: true, }, customUnsubscribeUrl: { @@ -117,9 +121,14 @@ export default { optional: true, }, }, + async additionalProps(props) { + props.listIds.hidden = this.all; + props.segmentIds.hidden = this.all; + return {}; + }, async run({ $ }) { if (!this.suppressionGroupId && !this.customUnsubscribeUrl) { - throw new ConfigurationError("You must provide either `Suppression Group Id` or the `Custom Unsubscribe URL`."); + throw new ConfigurationError("You must provide either `ASM Group ID` or the `Custom Unsubscribe URL`."); } try { const resp = await this.sendgrid.createSingleSend({ @@ -129,8 +138,12 @@ export default { categories: parseObject(this.categoryIds), send_at: this.sendAt, send_to: { - list_ids: parseObject(this.listIds), - segment_ids: parseObject(this.segmentIds), + list_ids: !this.all + ? parseObject(this.listIds) + : null, + segment_ids: !this.all + ? parseObject(this.segmentIds) + : null, all: this.all, }, email_config: { @@ -150,16 +163,10 @@ export default { $.export("$summary", `Successfully created single send ${this.name}`); return resp; } catch (e) { - if ( - e.response - && e.response.data - && e.response.data.errors - && e.response.data.errors.length > 0 - ) { - throw new ConfigurationError(e.response.data.errors[0].message); - } else { - throw new ConfigurationError("An unexpected error occurred."); - } + const errors = e.split("Unexpected error (status code: ERR_BAD_REQUEST):")[1]; + const errorJson = JSON.parse(errors); + + throw new ConfigurationError(errorJson.data.errors[0].message); } }, };