From 2e8a1935aa60762b47eb5c857b9262d01a8eacb3 Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Thu, 5 May 2022 21:46:07 -0300 Subject: [PATCH 01/19] [App:Postmark] Creating new action Creating "send email with template" --- .../send-email-with-template.mjs | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 components/postmark/actions/send-email-with-template/send-email-with-template.mjs diff --git a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs new file mode 100644 index 0000000000000..5a112bba23b1b --- /dev/null +++ b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs @@ -0,0 +1,182 @@ +import axios from "axios"; +import { axios as axiosPipedream } from "@pipedream/platform"; + +export default { + key: "postmark-send-email-with-template", + name: "Send an Email using a Template", + description: "Send an Email using a Template", + version: "0.1.12", + type: "action", + props: { + postmark: { + type: "app", + app: "postmark", + }, + template_alias: { + type: "string", + label: "Template", + description: "The template to use for this email.", + async options() { + return await axios({ + url: "https://api.postmarkapp.com/templates?count=500&offset=0", + headers: { + "X-Postmark-Server-Token": `${this.postmark.$auth.api_key}`, + "Accept": "application/json", + "Content-Type": "application/json", + }, + method: "GET", + }) + .then(({ data }) => + data.TotalCount + ? data.Templates.filter( + (obj) => obj.TemplateType === "Standard", + ).map((obj) => { + return { + label: obj.Name, + value: obj.Alias, + }; + }) + : [ + { + label: + "No templates found for this Postmark account. Create a template, then refresh this field.", + value: -1, + }, + ]) + .catch(() => [ + { + label: + "An error ocurred while fetching the list of templates for this Postmark account. Please try again.", + value: -2, + }, + ]); + }, + }, + template_model: { + type: "object", + label: "Template Model", + description: + "The model to be applied to the specified template to generate the email body and subject.", + }, + inline_css: { + type: "boolean", + label: "Inline CSS", + description: + "By default, if the specified template contains an HTMLBody, Postmark will apply the style blocks as inline attributes to the rendered HTML content. You may opt-out of this behavior by passing false for this request field.", + optional: true, + }, + from_email: { + type: "string", + label: "\"From\" email address", + description: + "The sender email address. Must have a registered and confirmed Sender Signature. To include a name, use the format 'Full Name <sender@domain.com>' for the address.", + }, + to_email: { + type: "string", + label: "Recipient email address(es)", + description: + "Recipient email address. Multiple addresses are comma separated. Max 50.", + }, + cc_email: { + type: "string", + label: "CC email address(es)", + description: + "Cc recipient email address. Multiple addresses are comma separated. Max 50.", + optional: true, + }, + bcc_email: { + type: "string", + label: "BCC email address(es)", + description: + "Bcc recipient email address. Multiple addresses are comma separated. Max 50.", + optional: true, + }, + tag: { + type: "string", + label: "Tag", + description: + "Email tag that allows you to categorize outgoing emails and get detailed statistics.", + optional: true, + }, + reply_to: { + type: "string", + label: "\"Reply To\" email address", + description: + "Reply To override email address. Defaults to the Reply To set in the sender signature.", + optional: true, + }, + custom_headers: { + type: "string[]", + label: "Custom Headers", + description: "List of custom headers to include.", + optional: true, + }, + track_opens: { + type: "boolean", + label: "Track Opens", + description: "Activate open tracking for this email.", + optional: true, + }, + track_links: { + type: "string", + label: "Track Links", + description: + "Activate link tracking for links in the HTML or Text bodies of this email.", + optional: true, + options: [ + "None", + "HtmlAndText", + "HtmlOnly", + "TextOnly", + ], + }, + // 'Attachments' pending - the API expects an array of objects, seemingly unsupported by props. + attachments: { + type: "string[]", + label: "Attachments", + description: "List of attachments", + optional: true, + }, + metadata: { + type: "object", + label: "Metadata", + description: "Custom metadata key/value pairs.", + optional: true, + }, + message_stream: { + type: "string", + label: "Message stream", + description: + "Set message stream ID that's used for sending. If not provided, message will default to the outbound transactional stream.", + optional: true, + }, + }, + async run({ $ }) { + return await axiosPipedream($, { + url: "https://api.postmarkapp.com/email/withTemplate", + headers: { + "X-Postmark-Server-Token": `${this.postmark.$auth.api_key}`, + "Content-Type": "application/json", + "Accept": "application/json", + }, + method: "POST", + data: { + TemplateAlias: this.template_alias, + TemplateModel: this.template_model, + InlineCSS: this.inline_css, + From: this.from_email, + To: this.to_email, + Cc: this.cc_email, + Bcc: this.bcc_email, + Tag: this.tag, + ReplyTo: this.reply_to, + Headers: this.custom_headers, + TrackOpens: this.track_opens, + TrackLinks: this.track_links, + Attachments: this.attachments, + Metadata: this.metadata, + MessageStream: this.message_stream, + }, + }); + }, +}; From 5965f3dab0efd1c4eb7ad700f7487f81b7c0ad96 Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Fri, 6 May 2022 18:44:53 -0300 Subject: [PATCH 02/19] [App:Postmark] Adjusting attachments prop Adjusted to a formatted string that is converted to an object --- .../send-email-with-template.mjs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs index 5a112bba23b1b..10e923de12f78 100644 --- a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs +++ b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs @@ -5,7 +5,7 @@ export default { key: "postmark-send-email-with-template", name: "Send an Email using a Template", description: "Send an Email using a Template", - version: "0.1.12", + version: "0.1.16", type: "action", props: { postmark: { @@ -39,7 +39,7 @@ export default { : [ { label: - "No templates found for this Postmark account. Create a template, then refresh this field.", + "No templates found for this Postmark account. Create a template, then refresh this field.", value: -1, }, ]) @@ -134,7 +134,13 @@ export default { attachments: { type: "string[]", label: "Attachments", - description: "List of attachments", + description: `Each attachment should be a string with the parameters separated by \`|\`, in the format: \`Name|Content|ContentType\` + \\ + - \`Name\` is the filename with extension, i.e. \`readme.txt\` + \\ + - \`Content\` is the base64-encoded string with the binary data for the file, i.e. \`dGVzdCBjb250ZW50\` + \\ + - \`ContentType\` is the MIME content type, i.e. \`text/plain\``, optional: true, }, metadata: { @@ -173,7 +179,14 @@ export default { Headers: this.custom_headers, TrackOpens: this.track_opens, TrackLinks: this.track_links, - Attachments: this.attachments, + Attachments: this.attachments?.map((str) => { + let params = str.split("|"); + return { + Name: params[0], + Content: params[1], + ContentType: params[2], + }; + }), Metadata: this.metadata, MessageStream: this.message_stream, }, From aa33ab69b1dca1098e7d76f51774c7025fa4269f Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Mon, 9 May 2022 20:42:49 -0300 Subject: [PATCH 03/19] [App:Postmark] Creating propDefinitions and methods --- .../send-email-with-template.mjs | 209 +++++++----------- components/postmark/postmark.app.mjs | 100 ++++++++- 2 files changed, 173 insertions(+), 136 deletions(-) diff --git a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs index 10e923de12f78..bf291aa617dce 100644 --- a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs +++ b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs @@ -1,55 +1,82 @@ import axios from "axios"; import { axios as axiosPipedream } from "@pipedream/platform"; +import postmark from "../../postmark.app.mjs"; + +let objSharedProps = {}; +[ + "from_email", + "to_email", + "cc_email", + "bcc_email", + "tag", + "reply_to", + "custom_headers", + "track_opens", + "track_links", + "attachments", + "metadata", + "message_stream", +].forEach((propName) => { + objSharedProps[propName] = { + propDefinition: [ + postmark, + propName, + ], + }; +}); + export default { key: "postmark-send-email-with-template", name: "Send an Email using a Template", description: "Send an Email using a Template", - version: "0.1.16", + version: "0.1.20", type: "action", - props: { - postmark: { - type: "app", - app: "postmark", + methods: { + async listTemplates() { + return await axios({ + url: "https://api.postmarkapp.com/templates?count=500&offset=0", + headers: { + "X-Postmark-Server-Token": `${this.postmark.$auth.api_key}`, + "Accept": "application/json", + "Content-Type": "application/json", + }, + method: "GET", + }) + .then(({ data }) => + data.TotalCount + ? data.Templates.filter( + (obj) => obj.TemplateType === "Standard", + ).map((obj) => { + return { + label: obj.Name, + value: obj.Alias, + }; + }) + : [ + { + label: + "No templates found for this Postmark account. Create a template, then refresh this field.", + value: -1, + }, + ]) + .catch(() => [ + { + label: + "An error ocurred while fetching the list of templates for this Postmark account. Please try again.", + value: -2, + }, + ]); }, + }, + props: { + postmark, template_alias: { type: "string", label: "Template", description: "The template to use for this email.", - async options() { - return await axios({ - url: "https://api.postmarkapp.com/templates?count=500&offset=0", - headers: { - "X-Postmark-Server-Token": `${this.postmark.$auth.api_key}`, - "Accept": "application/json", - "Content-Type": "application/json", - }, - method: "GET", - }) - .then(({ data }) => - data.TotalCount - ? data.Templates.filter( - (obj) => obj.TemplateType === "Standard", - ).map((obj) => { - return { - label: obj.Name, - value: obj.Alias, - }; - }) - : [ - { - label: - "No templates found for this Postmark account. Create a template, then refresh this field.", - value: -1, - }, - ]) - .catch(() => [ - { - label: - "An error ocurred while fetching the list of templates for this Postmark account. Please try again.", - value: -2, - }, - ]); + options() { + return this.listTemplates(); }, }, template_model: { @@ -65,97 +92,7 @@ export default { "By default, if the specified template contains an HTMLBody, Postmark will apply the style blocks as inline attributes to the rendered HTML content. You may opt-out of this behavior by passing false for this request field.", optional: true, }, - from_email: { - type: "string", - label: "\"From\" email address", - description: - "The sender email address. Must have a registered and confirmed Sender Signature. To include a name, use the format 'Full Name <sender@domain.com>' for the address.", - }, - to_email: { - type: "string", - label: "Recipient email address(es)", - description: - "Recipient email address. Multiple addresses are comma separated. Max 50.", - }, - cc_email: { - type: "string", - label: "CC email address(es)", - description: - "Cc recipient email address. Multiple addresses are comma separated. Max 50.", - optional: true, - }, - bcc_email: { - type: "string", - label: "BCC email address(es)", - description: - "Bcc recipient email address. Multiple addresses are comma separated. Max 50.", - optional: true, - }, - tag: { - type: "string", - label: "Tag", - description: - "Email tag that allows you to categorize outgoing emails and get detailed statistics.", - optional: true, - }, - reply_to: { - type: "string", - label: "\"Reply To\" email address", - description: - "Reply To override email address. Defaults to the Reply To set in the sender signature.", - optional: true, - }, - custom_headers: { - type: "string[]", - label: "Custom Headers", - description: "List of custom headers to include.", - optional: true, - }, - track_opens: { - type: "boolean", - label: "Track Opens", - description: "Activate open tracking for this email.", - optional: true, - }, - track_links: { - type: "string", - label: "Track Links", - description: - "Activate link tracking for links in the HTML or Text bodies of this email.", - optional: true, - options: [ - "None", - "HtmlAndText", - "HtmlOnly", - "TextOnly", - ], - }, - // 'Attachments' pending - the API expects an array of objects, seemingly unsupported by props. - attachments: { - type: "string[]", - label: "Attachments", - description: `Each attachment should be a string with the parameters separated by \`|\`, in the format: \`Name|Content|ContentType\` - \\ - - \`Name\` is the filename with extension, i.e. \`readme.txt\` - \\ - - \`Content\` is the base64-encoded string with the binary data for the file, i.e. \`dGVzdCBjb250ZW50\` - \\ - - \`ContentType\` is the MIME content type, i.e. \`text/plain\``, - optional: true, - }, - metadata: { - type: "object", - label: "Metadata", - description: "Custom metadata key/value pairs.", - optional: true, - }, - message_stream: { - type: "string", - label: "Message stream", - description: - "Set message stream ID that's used for sending. If not provided, message will default to the outbound transactional stream.", - optional: true, - }, + ...objSharedProps, }, async run({ $ }) { return await axiosPipedream($, { @@ -181,11 +118,13 @@ export default { TrackLinks: this.track_links, Attachments: this.attachments?.map((str) => { let params = str.split("|"); - return { - Name: params[0], - Content: params[1], - ContentType: params[2], - }; + return params.length === 3 + ? { + Name: params[0], + Content: params[1], + ContentType: params[2], + } + : JSON.parse(str); }), Metadata: this.metadata, MessageStream: this.message_stream, diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index d8b192d22a49d..11b1c8e012c3e 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -1,7 +1,105 @@ export default { type: "app", app: "postmark", - propDefinitions: {}, + propDefinitions: { + from_email: { + type: "string", + label: "\"From\" email address", + description: + "The sender email address. Must have a registered and confirmed Sender Signature. To include a name, use the format 'Full Name <sender@domain.com>' for the address.", + }, + to_email: { + type: "string", + label: "Recipient email address(es)", + description: + "Recipient email address. Multiple addresses are comma separated. Max 50.", + }, + cc_email: { + type: "string", + label: "CC email address(es)", + description: + "Cc recipient email address. Multiple addresses are comma separated. Max 50.", + optional: true, + }, + bcc_email: { + type: "string", + label: "BCC email address(es)", + description: + "Bcc recipient email address. Multiple addresses are comma separated. Max 50.", + optional: true, + }, + tag: { + type: "string", + label: "Tag", + description: + "Email tag that allows you to categorize outgoing emails and get detailed statistics.", + optional: true, + }, + reply_to: { + type: "string", + label: "\"Reply To\" email address", + description: + "Reply To override email address. Defaults to the Reply To set in the sender signature.", + optional: true, + }, + custom_headers: { + type: "string[]", + label: "Custom Headers", + description: "List of custom headers to include.", + optional: true, + }, + track_opens: { + type: "boolean", + label: "Track Opens", + description: "Activate open tracking for this email.", + optional: true, + }, + track_links: { + type: "string", + label: "Track Links", + description: + "Activate link tracking for links in the HTML or Text bodies of this email.", + optional: true, + options: [ + "None", + "HtmlAndText", + "HtmlOnly", + "TextOnly", + ], + }, + attachments: { + type: "string[]", + label: "Attachments", + description: `Each attachment should be a string with the parameters separated by a pipe character \`|\`, in the format: \`Name|Content|ContentType\`. Alternatively, you can pass a string representing an object. All three parameters are required: + \\ + \\ + \`Name\` - the filename with extension, i.e. \`readme.txt\` + \\ + \`Content\` - the base64-encoded string with the binary data for the file, i.e. \`dGVzdCBjb250ZW50\` + \\ + \`ContentType\` - the MIME content type, i.e. \`text/plain\` + \\ + \\ + Example with pipe-separated parameters: \`readme.txt|dGVzdCBjb250ZW50|text/plain\` + \\ + Example with JSON-stringified object: \`{"Name":"readme.txt","Content":"dGVzdCBjb250ZW50","ContentType":"text/plain"}\` + `, + optional: true, + }, + metadata: { + type: "object", + label: "Metadata", + description: "Custom metadata key/value pairs.", + optional: true, + }, + message_stream: { + type: "string", + label: "Message stream", + description: + "Set message stream ID that's used for sending. If not provided, message will default to the outbound transactional stream.", + optional: true, + }, + }, methods: { // this.$auth contains connected account data authKeys() { From 27b824dd9cce11d48450b3853440021211d07883 Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Mon, 9 May 2022 21:53:56 -0300 Subject: [PATCH 04/19] [App:Postmark] Updating 'send-single-email' action Reusing propDefinitions and methods across both Postmark actions --- .../send-email-with-template.mjs | 66 ++--------- .../send-single-email/send-single-email.mjs | 103 ++++++++---------- components/postmark/postmark.app.mjs | 67 ++++++++++++ 3 files changed, 120 insertions(+), 116 deletions(-) diff --git a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs index bf291aa617dce..2a81196575d31 100644 --- a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs +++ b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs @@ -1,23 +1,8 @@ -import axios from "axios"; -import { axios as axiosPipedream } from "@pipedream/platform"; - +import { axios } from "@pipedream/platform"; import postmark from "../../postmark.app.mjs"; let objSharedProps = {}; -[ - "from_email", - "to_email", - "cc_email", - "bcc_email", - "tag", - "reply_to", - "custom_headers", - "track_opens", - "track_links", - "attachments", - "metadata", - "message_stream", -].forEach((propName) => { +postmark.methods.listSharedProps().forEach((propName) => { objSharedProps[propName] = { propDefinition: [ postmark, @@ -28,47 +13,10 @@ let objSharedProps = {}; export default { key: "postmark-send-email-with-template", - name: "Send an Email using a Template", - description: "Send an Email using a Template", - version: "0.1.20", + name: "Send an email with template", + description: "Send an email with Postmark using a template", + version: "0.1.21", type: "action", - methods: { - async listTemplates() { - return await axios({ - url: "https://api.postmarkapp.com/templates?count=500&offset=0", - headers: { - "X-Postmark-Server-Token": `${this.postmark.$auth.api_key}`, - "Accept": "application/json", - "Content-Type": "application/json", - }, - method: "GET", - }) - .then(({ data }) => - data.TotalCount - ? data.Templates.filter( - (obj) => obj.TemplateType === "Standard", - ).map((obj) => { - return { - label: obj.Name, - value: obj.Alias, - }; - }) - : [ - { - label: - "No templates found for this Postmark account. Create a template, then refresh this field.", - value: -1, - }, - ]) - .catch(() => [ - { - label: - "An error ocurred while fetching the list of templates for this Postmark account. Please try again.", - value: -2, - }, - ]); - }, - }, props: { postmark, template_alias: { @@ -76,7 +24,7 @@ export default { label: "Template", description: "The template to use for this email.", options() { - return this.listTemplates(); + return this.postmark.listTemplates(); }, }, template_model: { @@ -95,7 +43,7 @@ export default { ...objSharedProps, }, async run({ $ }) { - return await axiosPipedream($, { + return await axios($, { url: "https://api.postmarkapp.com/email/withTemplate", headers: { "X-Postmark-Server-Token": `${this.postmark.$auth.api_key}`, diff --git a/components/postmark/actions/send-single-email/send-single-email.mjs b/components/postmark/actions/send-single-email/send-single-email.mjs index ecae073901e74..d2ab8be4f6d7f 100644 --- a/components/postmark/actions/send-single-email/send-single-email.mjs +++ b/components/postmark/actions/send-single-email/send-single-email.mjs @@ -1,69 +1,45 @@ // legacy_hash_id: a_8KiGrJ import { axios } from "@pipedream/platform"; +import postmark from "../../postmark.app.mjs"; + +let objSharedProps = {}; +postmark.methods.listSharedProps().forEach((propName) => { + objSharedProps[propName] = { + propDefinition: [ + postmark, + propName, + ], + }; +}); export default { key: "postmark-send-single-email", - name: "Send an Email with Postmark to a Single Recipient", - description: "Send an Email with Postmark to a Single Recipient", - version: "0.1.1", + name: "Send an email", + description: "Send an email with Postmark", + version: "0.1.2", type: "action", props: { - postmark: { - type: "app", - app: "postmark", - }, - from_email: { - type: "string", - label: "From Email", - }, - to_email: { - type: "string", - label: "To Email", - }, - cc_email: { - type: "string", - label: "CC Email", - optional: true, - }, - bcc_email: { - type: "string", - label: "BCC Email", - optional: true, - }, + postmark, subject: { type: "string", label: "Subject", - }, - tag: { - type: "string", - label: "Tag", - optional: true, + description: "Email subject", }, html_body: { type: "string", - label: "Html Body", + label: "HTML Body", + description: + "HTML email message. Required if no `TextBody` is specified.", optional: true, }, text_body: { type: "string", label: "Text Body", + description: + "Plain text email message. Required if no `HtmlBody` is specified.", optional: true, }, - reply_to: { - type: "string", - label: "Reply To Email", - optional: true, - }, - track_opens: { - type: "boolean", - optional: true, - }, - track_links: { - type: "string", - label: "Track Links", - description: "Activate link tracking for links in the HTML or Text bodies of this email. Possible options: None HtmlAndText HtmlOnly TextOnly", - optional: true, - }, + ...objSharedProps, }, async run({ $ }) { return await axios($, { @@ -75,17 +51,30 @@ export default { }, method: "POST", data: { - "From": this.from_email, - "To": this.to_email, - "Cc": this.cc_email, - "Bcc": this.bcc_email, - "Subject": this.subject, - "Tag": this.tag, - "HtmlBody": this.html_body, - "TextBody": this.text_body, - "ReplyTo": this.reply_to, - "TrackOpens": this.track_opens, - "TrackLinks": this.track_links, + Subject: this.subject, + HtmlBody: this.html_body, + TextBody: this.text_body, + From: this.from_email, + To: this.to_email, + Cc: this.cc_email, + Bcc: this.bcc_email, + Tag: this.tag, + ReplyTo: this.reply_to, + Headers: this.custom_headers, + TrackOpens: this.track_opens, + TrackLinks: this.track_links, + Attachments: this.attachments?.map((str) => { + let params = str.split("|"); + return params.length === 3 + ? { + Name: params[0], + Content: params[1], + ContentType: params[2], + } + : JSON.parse(str); + }), + Metadata: this.metadata, + MessageStream: this.message_stream, }, }); }, diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index 11b1c8e012c3e..1ae45746eac2e 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -1,3 +1,5 @@ +import axios from "axios"; + export default { type: "app", app: "postmark", @@ -105,5 +107,70 @@ export default { authKeys() { console.log(Object.keys(this.$auth)); }, + async listTemplates() { + return await axios({ + url: "https://api.postmarkapp.com/templates?count=500&offset=0", + headers: { + "X-Postmark-Server-Token": `${this.postmark.$auth.api_key}`, + "Accept": "application/json", + "Content-Type": "application/json", + }, + method: "GET", + }) + .then(({ data }) => + data.TotalCount + ? data.Templates.filter( + (obj) => obj.TemplateType === "Standard", + ).map((obj) => { + return { + label: obj.Name, + value: obj.Alias, + }; + }) + : [ + { + label: + "No templates found for this Postmark account. Create a template, then refresh this field.", + value: -1, + }, + ]) + .catch(() => [ + { + label: + "An error ocurred while fetching the list of templates for this Postmark account. Please try again.", + value: -2, + }, + ]); + }, + listSharedProps() { + return [ + "from_email", + "to_email", + "cc_email", + "bcc_email", + "tag", + "reply_to", + "custom_headers", + "track_opens", + "track_links", + "attachments", + "metadata", + "message_stream", + ]; + }, + getSharedPropDefinitions() { + const SHARED_PROPS = this.listSharedProps(); + + let obj = {}; + SHARED_PROPS.forEach((propName) => { + obj[propName] = { + propDefinition: [ + this, + propName, + ], + }; + }); + return obj; + }, }, }; From e8463ef72a6787e36477be5cc01a49425673fa1b Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Mon, 9 May 2022 22:47:53 -0300 Subject: [PATCH 05/19] [App:Postmark] Creating shared request for actions Also fixed a reference error. --- .../send-email-with-template.mjs | 41 ++-------------- .../send-single-email/send-single-email.mjs | 47 ++++-------------- components/postmark/postmark.app.mjs | 48 ++++++++++++++----- 3 files changed, 48 insertions(+), 88 deletions(-) diff --git a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs index 2a81196575d31..3e9abf635c86c 100644 --- a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs +++ b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs @@ -1,4 +1,3 @@ -import { axios } from "@pipedream/platform"; import postmark from "../../postmark.app.mjs"; let objSharedProps = {}; @@ -15,7 +14,7 @@ export default { key: "postmark-send-email-with-template", name: "Send an email with template", description: "Send an email with Postmark using a template", - version: "0.1.21", + version: "0.1.23", type: "action", props: { postmark, @@ -43,40 +42,10 @@ export default { ...objSharedProps, }, async run({ $ }) { - return await axios($, { - url: "https://api.postmarkapp.com/email/withTemplate", - headers: { - "X-Postmark-Server-Token": `${this.postmark.$auth.api_key}`, - "Content-Type": "application/json", - "Accept": "application/json", - }, - method: "POST", - data: { - TemplateAlias: this.template_alias, - TemplateModel: this.template_model, - InlineCSS: this.inline_css, - From: this.from_email, - To: this.to_email, - Cc: this.cc_email, - Bcc: this.bcc_email, - Tag: this.tag, - ReplyTo: this.reply_to, - Headers: this.custom_headers, - TrackOpens: this.track_opens, - TrackLinks: this.track_links, - Attachments: this.attachments?.map((str) => { - let params = str.split("|"); - return params.length === 3 - ? { - Name: params[0], - Content: params[1], - ContentType: params[2], - } - : JSON.parse(str); - }), - Metadata: this.metadata, - MessageStream: this.message_stream, - }, + return this.postmark.sharedRequest($, this, "email/withTemplate", { + TemplateAlias: this.template_alias, + TemplateModel: this.template_model, + InlineCSS: this.inline_css, }); }, }; diff --git a/components/postmark/actions/send-single-email/send-single-email.mjs b/components/postmark/actions/send-single-email/send-single-email.mjs index d2ab8be4f6d7f..0754ee6898b1d 100644 --- a/components/postmark/actions/send-single-email/send-single-email.mjs +++ b/components/postmark/actions/send-single-email/send-single-email.mjs @@ -1,5 +1,4 @@ // legacy_hash_id: a_8KiGrJ -import { axios } from "@pipedream/platform"; import postmark from "../../postmark.app.mjs"; let objSharedProps = {}; @@ -16,66 +15,36 @@ export default { key: "postmark-send-single-email", name: "Send an email", description: "Send an email with Postmark", - version: "0.1.2", + version: "0.1.4", type: "action", props: { postmark, subject: { type: "string", label: "Subject", - description: "Email subject", + description: "Email subject.", }, html_body: { type: "string", label: "HTML Body", description: - "HTML email message. Required if no `TextBody` is specified.", + "HTML email message. **Required** if no `TextBody` is specified.", optional: true, }, text_body: { type: "string", label: "Text Body", description: - "Plain text email message. Required if no `HtmlBody` is specified.", + "Plain text email message. **Required** if no `HtmlBody` is specified.", optional: true, }, ...objSharedProps, }, async run({ $ }) { - return await axios($, { - url: "https://api.postmarkapp.com/email", - headers: { - "X-Postmark-Server-Token": `${this.postmark.$auth.api_key}`, - "Content-Type": "application/json", - "Accept": "application/json", - }, - method: "POST", - data: { - Subject: this.subject, - HtmlBody: this.html_body, - TextBody: this.text_body, - From: this.from_email, - To: this.to_email, - Cc: this.cc_email, - Bcc: this.bcc_email, - Tag: this.tag, - ReplyTo: this.reply_to, - Headers: this.custom_headers, - TrackOpens: this.track_opens, - TrackLinks: this.track_links, - Attachments: this.attachments?.map((str) => { - let params = str.split("|"); - return params.length === 3 - ? { - Name: params[0], - Content: params[1], - ContentType: params[2], - } - : JSON.parse(str); - }), - Metadata: this.metadata, - MessageStream: this.message_stream, - }, + return this.postmark.sharedRequest($, this, "email", { + Subject: this.subject, + HtmlBody: this.html_body, + TextBody: this.text_body, }); }, }; diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index 1ae45746eac2e..06df6593627c4 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -1,4 +1,5 @@ import axios from "axios"; +import { axios as axiosPipedream } from "@pipedream/platform"; export default { type: "app", @@ -111,7 +112,7 @@ export default { return await axios({ url: "https://api.postmarkapp.com/templates?count=500&offset=0", headers: { - "X-Postmark-Server-Token": `${this.postmark.$auth.api_key}`, + "X-Postmark-Server-Token": `${this.$auth.api_key}`, "Accept": "application/json", "Content-Type": "application/json", }, @@ -158,19 +159,40 @@ export default { "message_stream", ]; }, - getSharedPropDefinitions() { - const SHARED_PROPS = this.listSharedProps(); - - let obj = {}; - SHARED_PROPS.forEach((propName) => { - obj[propName] = { - propDefinition: [ - this, - propName, - ], - }; + async sharedRequest($, action, endpoint, uniqueProps) { + return await axiosPipedream($, { + url: `https://api.postmarkapp.com/${endpoint}`, + headers: { + "X-Postmark-Server-Token": `${this.$auth.api_key}`, + "Content-Type": "application/json", + "Accept": "application/json", + }, + method: "POST", + data: { + ...uniqueProps, + From: action.from_email, + To: action.to_email, + Cc: action.cc_email, + Bcc: action.bcc_email, + Tag: action.tag, + ReplyTo: action.reply_to, + Headers: action.custom_headers, + TrackOpens: action.track_opens, + TrackLinks: action.track_links, + Attachments: action.attachments?.map((str) => { + let params = str.split("|"); + return params.length === 3 + ? { + Name: params[0], + Content: params[1], + ContentType: params[2], + } + : JSON.parse(str); + }), + Metadata: action.metadata, + MessageStream: action.message_stream, + }, }); - return obj; }, }, }; From c55407c4743cdd96d05f0a5f3b4f0c3d5470e65c Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Thu, 12 May 2022 02:51:35 -0300 Subject: [PATCH 06/19] [App:Postmark] Creating source: "new inbound email received" --- components/postmark/postmark.app.mjs | 47 ++++++++++++++++++- .../new-inbound-email-received.mjs | 33 +++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index 06df6593627c4..6e9ca9b70a0c7 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -112,7 +112,7 @@ export default { return await axios({ url: "https://api.postmarkapp.com/templates?count=500&offset=0", headers: { - "X-Postmark-Server-Token": `${this.$auth.api_key}`, + "X-Postmark-Server-Token": this.$auth.api_key, "Accept": "application/json", "Content-Type": "application/json", }, @@ -163,7 +163,7 @@ export default { return await axiosPipedream($, { url: `https://api.postmarkapp.com/${endpoint}`, headers: { - "X-Postmark-Server-Token": `${this.$auth.api_key}`, + "X-Postmark-Server-Token": this.$auth.api_key, "Content-Type": "application/json", "Accept": "application/json", }, @@ -194,5 +194,48 @@ export default { }, }); }, + async setInboundWebhookUrl(hookUrl) { + return await axios + .put( + "https://api.postmarkapp.com/server", + { + InboundHookUrl: hookUrl, + }, + { + headers: { + "X-Postmark-Server-Token": "a414a2ce-8779-4373-a281-197e7830353f", + "Content-Type": "application/json", + "Accept": "application/json", + }, + }, + ) + .then(({ data }) => data); + }, + // async webhookRequest(params) { + // let { endpoint, method, body } = params; + // return await axios({ + // url: `https://api.postmarkapp.com/webhooks${endpoint ?? ""}`, + // headers: { + // "X-Postmark-Server-Token": `${this.$auth.api_key}`, + // "Content-Type": "application/json", + // Accept: "application/json", + // }, + // body, + // method, + // }).then(({ data }) => data); + // }, + // async createWebhook(pipedreamUrl, type) { + // return this.webhookRequest({ + // method: "POST", + // body: { + // Url: pipedreamUrl, + // Triggers: { + // [type]: { + // Enabled: true, + // }, + // }, + // }, + // }); + // }, }, }; diff --git a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs new file mode 100644 index 0000000000000..f8911c026d812 --- /dev/null +++ b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs @@ -0,0 +1,33 @@ +import postmark from "../../postmark.app.mjs"; + +export default { + key: "new-inbound-email-received", + name: "New inbound email received", + description: + "Emit new event when an email is received by the Postmark server", + version: "0.0.1", + type: "source", + props: { + postmark, + db: "$.service.db", + http: { + type: "$.interface.http", + customResponse: true, + }, + }, + hooks: { + async activate() { + return this.postmark.setInboundWebhookUrl(this.http.endpoint); + }, + async deactivate() { + return ""; + }, + }, + async run(event) { + this.http.respond({ + status: 200, + }); + + this.$emit(event); + }, +}; From 01b2ec3d6664a9979d161ec936f9a09b04ba1ffb Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Thu, 12 May 2022 21:54:30 -0300 Subject: [PATCH 07/19] [App:Postmark] Creating 'new email opened' source --- components/postmark/postmark.app.mjs | 32 +----------- .../new-email-opened/new-email-opened.mjs | 51 +++++++++++++++++++ .../new-inbound-email-received.mjs | 9 ++-- 3 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 components/postmark/sources/new-email-opened/new-email-opened.mjs diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index 6e9ca9b70a0c7..5b01da28ddfbc 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -194,13 +194,11 @@ export default { }, }); }, - async setInboundWebhookUrl(hookUrl) { + async setServerInfo(params) { return await axios .put( "https://api.postmarkapp.com/server", - { - InboundHookUrl: hookUrl, - }, + params, { headers: { "X-Postmark-Server-Token": "a414a2ce-8779-4373-a281-197e7830353f", @@ -211,31 +209,5 @@ export default { ) .then(({ data }) => data); }, - // async webhookRequest(params) { - // let { endpoint, method, body } = params; - // return await axios({ - // url: `https://api.postmarkapp.com/webhooks${endpoint ?? ""}`, - // headers: { - // "X-Postmark-Server-Token": `${this.$auth.api_key}`, - // "Content-Type": "application/json", - // Accept: "application/json", - // }, - // body, - // method, - // }).then(({ data }) => data); - // }, - // async createWebhook(pipedreamUrl, type) { - // return this.webhookRequest({ - // method: "POST", - // body: { - // Url: pipedreamUrl, - // Triggers: { - // [type]: { - // Enabled: true, - // }, - // }, - // }, - // }); - // }, }, }; diff --git a/components/postmark/sources/new-email-opened/new-email-opened.mjs b/components/postmark/sources/new-email-opened/new-email-opened.mjs new file mode 100644 index 0000000000000..ba9e8272beff0 --- /dev/null +++ b/components/postmark/sources/new-email-opened/new-email-opened.mjs @@ -0,0 +1,51 @@ +import postmark from "../../postmark.app.mjs"; + +export default { + key: "new-email-opened", + name: "New email opened", + description: "Emit new event when an email is opened by a recipient", + version: "0.0.1", + type: "source", + props: { + postmark, + http: { + type: "$.interface.http", + customResponse: true, + }, + trackOpensByDefault: { + type: "boolean", + label: "Track opens by default", + description: `If enabled, all emails being sent through this server will have open tracking enabled. + \\ + Otherwise, only emails that have open tracking explicitly set will trigger this event when opened.`, + }, + postFirstOpenOnly: { + type: "boolean", + label: "Track first open only", + description: `If enabled, an event will only be emitted the first time the recipient opens the email. + \\ + Otherwise, the event will be emitted every time an open occurs.`, + }, + }, + hooks: { + async activate() { + return this.postmark.setServerInfo({ + OpenHookUrl: this.http.endpoint, + PostFirstOpenOnly: this.postFirstOpenOnly, + TrackOpens: this.trackOpensByDefault, + }); + }, + async deactivate() { + return this.postmark.setServerInfo({ + OpenHookUrl: "", + }); + }, + }, + async run(event) { + this.http.respond({ + status: 200, + }); + + this.$emit(event); + }, +}; diff --git a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs index f8911c026d812..92e74d0ec1c94 100644 --- a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs +++ b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs @@ -9,7 +9,6 @@ export default { type: "source", props: { postmark, - db: "$.service.db", http: { type: "$.interface.http", customResponse: true, @@ -17,10 +16,14 @@ export default { }, hooks: { async activate() { - return this.postmark.setInboundWebhookUrl(this.http.endpoint); + return this.postmark.setServerInfo({ + InboundHookUrl: this.http.endpoint, + }); }, async deactivate() { - return ""; + return this.postmark.setServerInfo({ + InboundHookUrl: "", + }); }, }, async run(event) { From 31ee9d393bec379a4e51054dd4e5b5e97b09d889 Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Fri, 13 May 2022 11:49:21 -0300 Subject: [PATCH 08/19] [App:Postmark] Creating getHeaders method --- .../send-email-with-template.mjs | 2 +- .../send-single-email/send-single-email.mjs | 2 +- components/postmark/postmark.app.mjs | 27 ++++++++----------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs index 3e9abf635c86c..f2b4cc96e86c9 100644 --- a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs +++ b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs @@ -42,7 +42,7 @@ export default { ...objSharedProps, }, async run({ $ }) { - return this.postmark.sharedRequest($, this, "email/withTemplate", { + return this.postmark.sharedActionRequest($, this, "email/withTemplate", { TemplateAlias: this.template_alias, TemplateModel: this.template_model, InlineCSS: this.inline_css, diff --git a/components/postmark/actions/send-single-email/send-single-email.mjs b/components/postmark/actions/send-single-email/send-single-email.mjs index 0754ee6898b1d..c372db783f6b5 100644 --- a/components/postmark/actions/send-single-email/send-single-email.mjs +++ b/components/postmark/actions/send-single-email/send-single-email.mjs @@ -41,7 +41,7 @@ export default { ...objSharedProps, }, async run({ $ }) { - return this.postmark.sharedRequest($, this, "email", { + return this.postmark.sharedActionRequest($, this, "email", { Subject: this.subject, HtmlBody: this.html_body, TextBody: this.text_body, diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index 5b01da28ddfbc..b2c90596af69a 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -111,11 +111,7 @@ export default { async listTemplates() { return await axios({ url: "https://api.postmarkapp.com/templates?count=500&offset=0", - headers: { - "X-Postmark-Server-Token": this.$auth.api_key, - "Accept": "application/json", - "Content-Type": "application/json", - }, + headers: this.getHeaders(), method: "GET", }) .then(({ data }) => @@ -143,6 +139,13 @@ export default { }, ]); }, + getHeaders() { + return { + "X-Postmark-Server-Token": this.$auth.api_key, + "Content-Type": "application/json", + "Accept": "application/json", + }; + }, listSharedProps() { return [ "from_email", @@ -159,14 +162,10 @@ export default { "message_stream", ]; }, - async sharedRequest($, action, endpoint, uniqueProps) { + async sharedActionRequest($, action, endpoint, uniqueProps) { return await axiosPipedream($, { url: `https://api.postmarkapp.com/${endpoint}`, - headers: { - "X-Postmark-Server-Token": this.$auth.api_key, - "Content-Type": "application/json", - "Accept": "application/json", - }, + headers: this.getHeaders(), method: "POST", data: { ...uniqueProps, @@ -200,11 +199,7 @@ export default { "https://api.postmarkapp.com/server", params, { - headers: { - "X-Postmark-Server-Token": "a414a2ce-8779-4373-a281-197e7830353f", - "Content-Type": "application/json", - "Accept": "application/json", - }, + headers: this.getHeaders(), }, ) .then(({ data }) => data); From ad404d84da8651dc6849228c372461abbaec9f52 Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Fri, 13 May 2022 12:12:28 -0300 Subject: [PATCH 09/19] [App:Postmark] Fixing source key names --- .../postmark/sources/new-email-opened/new-email-opened.mjs | 2 +- .../new-inbound-email-received/new-inbound-email-received.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/postmark/sources/new-email-opened/new-email-opened.mjs b/components/postmark/sources/new-email-opened/new-email-opened.mjs index ba9e8272beff0..ce791451b48aa 100644 --- a/components/postmark/sources/new-email-opened/new-email-opened.mjs +++ b/components/postmark/sources/new-email-opened/new-email-opened.mjs @@ -1,7 +1,7 @@ import postmark from "../../postmark.app.mjs"; export default { - key: "new-email-opened", + key: "postmark-new-email-opened", name: "New email opened", description: "Emit new event when an email is opened by a recipient", version: "0.0.1", diff --git a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs index 92e74d0ec1c94..f64315c179c52 100644 --- a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs +++ b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs @@ -1,7 +1,7 @@ import postmark from "../../postmark.app.mjs"; export default { - key: "new-inbound-email-received", + key: "postmark-new-inbound-email-received", name: "New inbound email received", description: "Emit new event when an email is received by the Postmark server", From 668b886dfcb030f6f5991cfade5e9723fae27301 Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Mon, 16 May 2022 21:24:14 -0300 Subject: [PATCH 10/19] [App:Postmark] PR changes requested #1 --- .../send-email-with-template/send-email-with-template.mjs | 4 ++-- .../actions/send-single-email/send-single-email.mjs | 4 ++-- components/postmark/postmark.app.mjs | 7 +++---- .../postmark/sources/new-email-opened/new-email-opened.mjs | 4 ++-- .../new-inbound-email-received.mjs | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs index f2b4cc96e86c9..ccef7cf909366 100644 --- a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs +++ b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs @@ -12,8 +12,8 @@ postmark.methods.listSharedProps().forEach((propName) => { export default { key: "postmark-send-email-with-template", - name: "Send an email with template", - description: "Send an email with Postmark using a template", + name: "Send Email With Template", + description: "Send a single email with Postmark using a template [(See docs here)](https://postmarkapp.com/developer/api/templates-api#email-with-template)", version: "0.1.23", type: "action", props: { diff --git a/components/postmark/actions/send-single-email/send-single-email.mjs b/components/postmark/actions/send-single-email/send-single-email.mjs index c372db783f6b5..8cb4305d7acb1 100644 --- a/components/postmark/actions/send-single-email/send-single-email.mjs +++ b/components/postmark/actions/send-single-email/send-single-email.mjs @@ -13,8 +13,8 @@ postmark.methods.listSharedProps().forEach((propName) => { export default { key: "postmark-send-single-email", - name: "Send an email", - description: "Send an email with Postmark", + name: "Send Single Email", + description: "Send a single email with Postmark [(See docs here)](https://postmarkapp.com/developer/api/email-api#send-a-single-email)", version: "0.1.4", type: "action", props: { diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index b2c90596af69a..c78442d03900e 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -104,9 +104,8 @@ export default { }, }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _apikey() { + return this.$auth.api_key; }, async listTemplates() { return await axios({ @@ -141,7 +140,7 @@ export default { }, getHeaders() { return { - "X-Postmark-Server-Token": this.$auth.api_key, + "X-Postmark-Server-Token": this._apikey(), "Content-Type": "application/json", "Accept": "application/json", }; diff --git a/components/postmark/sources/new-email-opened/new-email-opened.mjs b/components/postmark/sources/new-email-opened/new-email-opened.mjs index ce791451b48aa..b8effb290d924 100644 --- a/components/postmark/sources/new-email-opened/new-email-opened.mjs +++ b/components/postmark/sources/new-email-opened/new-email-opened.mjs @@ -2,8 +2,8 @@ import postmark from "../../postmark.app.mjs"; export default { key: "postmark-new-email-opened", - name: "New email opened", - description: "Emit new event when an email is opened by a recipient", + name: "New Email Opened", + description: "Emit new event when an email is opened by a recipient [(See docs here)](https://postmarkapp.com/developer/webhooks/open-tracking-webhook)", version: "0.0.1", type: "source", props: { diff --git a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs index f64315c179c52..7747265080627 100644 --- a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs +++ b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs @@ -2,9 +2,9 @@ import postmark from "../../postmark.app.mjs"; export default { key: "postmark-new-inbound-email-received", - name: "New inbound email received", + name: "New Inbound Email Received", description: - "Emit new event when an email is received by the Postmark server", + "Emit new event when an email is received by the Postmark server [(See docs here)](https://postmarkapp.com/developer/webhooks/inbound-webhook)", version: "0.0.1", type: "source", props: { From f943b857457a9a398246c3f552c606d5214d3b6e Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Tue, 17 May 2022 23:12:55 -0300 Subject: [PATCH 11/19] [App:Postmark] PR changes requested #2 --- .../send-email-with-template.mjs | 16 +-- .../send-single-email/send-single-email.mjs | 2 +- components/postmark/postmark.app.mjs | 125 +++++++++--------- .../new-email-opened/new-email-opened.mjs | 13 +- .../new-inbound-email-received.mjs | 13 +- 5 files changed, 91 insertions(+), 78 deletions(-) diff --git a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs index ccef7cf909366..d198caf75f535 100644 --- a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs +++ b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs @@ -14,17 +14,15 @@ export default { key: "postmark-send-email-with-template", name: "Send Email With Template", description: "Send a single email with Postmark using a template [(See docs here)](https://postmarkapp.com/developer/api/templates-api#email-with-template)", - version: "0.1.23", + version: "0.0.1", type: "action", props: { postmark, - template_alias: { - type: "string", - label: "Template", - description: "The template to use for this email.", - options() { - return this.postmark.listTemplates(); - }, + templateAlias: { + propDefinition: [ + postmark, + "templateAlias", + ], }, template_model: { type: "object", @@ -43,7 +41,7 @@ export default { }, async run({ $ }) { return this.postmark.sharedActionRequest($, this, "email/withTemplate", { - TemplateAlias: this.template_alias, + TemplateAlias: this.templateAlias, TemplateModel: this.template_model, InlineCSS: this.inline_css, }); diff --git a/components/postmark/actions/send-single-email/send-single-email.mjs b/components/postmark/actions/send-single-email/send-single-email.mjs index 8cb4305d7acb1..d74b20c390723 100644 --- a/components/postmark/actions/send-single-email/send-single-email.mjs +++ b/components/postmark/actions/send-single-email/send-single-email.mjs @@ -15,7 +15,7 @@ export default { key: "postmark-send-single-email", name: "Send Single Email", description: "Send a single email with Postmark [(See docs here)](https://postmarkapp.com/developer/api/email-api#send-a-single-email)", - version: "0.1.4", + version: "0.2.0", type: "action", props: { postmark, diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index c78442d03900e..9f1c64a5f53bd 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -5,26 +5,34 @@ export default { type: "app", app: "postmark", propDefinitions: { - from_email: { + templateAlias: { + type: "string", + label: "Template", + description: "The template to use for this email.", + async options() { + return this.listTemplates(); + }, + }, + fromEmail: { type: "string", label: "\"From\" email address", description: "The sender email address. Must have a registered and confirmed Sender Signature. To include a name, use the format 'Full Name <sender@domain.com>' for the address.", }, - to_email: { + toEmail: { type: "string", label: "Recipient email address(es)", description: "Recipient email address. Multiple addresses are comma separated. Max 50.", }, - cc_email: { + ccEmail: { type: "string", label: "CC email address(es)", description: "Cc recipient email address. Multiple addresses are comma separated. Max 50.", optional: true, }, - bcc_email: { + bccEmail: { type: "string", label: "BCC email address(es)", description: @@ -38,26 +46,26 @@ export default { "Email tag that allows you to categorize outgoing emails and get detailed statistics.", optional: true, }, - reply_to: { + replyTo: { type: "string", label: "\"Reply To\" email address", description: "Reply To override email address. Defaults to the Reply To set in the sender signature.", optional: true, }, - custom_headers: { + customHeaders: { type: "string[]", label: "Custom Headers", description: "List of custom headers to include.", optional: true, }, - track_opens: { + trackOpens: { type: "boolean", label: "Track Opens", description: "Activate open tracking for this email.", optional: true, }, - track_links: { + trackLinks: { type: "string", label: "Track Links", description: @@ -95,7 +103,7 @@ export default { description: "Custom metadata key/value pairs.", optional: true, }, - message_stream: { + messageStream: { type: "string", label: "Message stream", description: @@ -108,35 +116,21 @@ export default { return this.$auth.api_key; }, async listTemplates() { - return await axios({ - url: "https://api.postmarkapp.com/templates?count=500&offset=0", + const { data } = await axios({ + url: "https://api.postmarkapp.com/templates?Count=500&Offset=0&TemplateType=Standard", headers: this.getHeaders(), method: "GET", - }) - .then(({ data }) => - data.TotalCount - ? data.Templates.filter( - (obj) => obj.TemplateType === "Standard", - ).map((obj) => { - return { - label: obj.Name, - value: obj.Alias, - }; - }) - : [ - { - label: - "No templates found for this Postmark account. Create a template, then refresh this field.", - value: -1, - }, - ]) - .catch(() => [ - { - label: - "An error ocurred while fetching the list of templates for this Postmark account. Please try again.", - value: -2, - }, - ]); + }); + + return data.TotalCount + ? data.Templates.map((obj) => { + return { + label: obj.Name, + value: obj.Alias, + }; + }) + : []; + }, getHeaders() { return { @@ -145,20 +139,32 @@ export default { "Accept": "application/json", }; }, + getAttachmentData(attachments) { + return attachments?.map((str) => { + let params = str.split("|"); + return params.length === 3 + ? { + Name: params[0], + Content: params[1], + ContentType: params[2], + } + : JSON.parse(str); + }); + }, listSharedProps() { return [ - "from_email", - "to_email", - "cc_email", - "bcc_email", + "fromEmail", + "toEmail", + "ccEmail", + "bccEmail", "tag", - "reply_to", - "custom_headers", - "track_opens", - "track_links", + "replyTo", + "customHeaders", + "trackOpens", + "trackLinks", "attachments", "metadata", - "message_stream", + "messageStream", ]; }, async sharedActionRequest($, action, endpoint, uniqueProps) { @@ -168,27 +174,18 @@ export default { method: "POST", data: { ...uniqueProps, - From: action.from_email, - To: action.to_email, - Cc: action.cc_email, - Bcc: action.bcc_email, + From: action.fromEmail, + To: action.toEmail, + Cc: action.ccEmail, + Bcc: action.bccEmail, Tag: action.tag, - ReplyTo: action.reply_to, - Headers: action.custom_headers, - TrackOpens: action.track_opens, - TrackLinks: action.track_links, - Attachments: action.attachments?.map((str) => { - let params = str.split("|"); - return params.length === 3 - ? { - Name: params[0], - Content: params[1], - ContentType: params[2], - } - : JSON.parse(str); - }), + ReplyTo: action.replyTo, + Headers: action.customHeaders, + TrackOpens: action.trackOpens, + TrackLinks: action.trackLinks, + Attachments: this.getAttachmentData(this.attachments), Metadata: action.metadata, - MessageStream: action.message_stream, + MessageStream: action.messageStream, }, }); }, diff --git a/components/postmark/sources/new-email-opened/new-email-opened.mjs b/components/postmark/sources/new-email-opened/new-email-opened.mjs index b8effb290d924..f09bdf0d05861 100644 --- a/components/postmark/sources/new-email-opened/new-email-opened.mjs +++ b/components/postmark/sources/new-email-opened/new-email-opened.mjs @@ -41,11 +41,20 @@ export default { }); }, }, - async run(event) { + async run(data) { this.http.respond({ status: 200, }); - this.$emit(event); + let date = new Date(data.ReceivedAt); + let msgId = data.MessageID; + + let id = `${msgId}-${date.toISOString()}`; + + this.$emit(data, { + id, + summary: data.Subject, + ts: date.valueOf(), + }); }, }; diff --git a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs index 7747265080627..7180fae82cb6c 100644 --- a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs +++ b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs @@ -26,11 +26,20 @@ export default { }); }, }, - async run(event) { + async run(data) { this.http.respond({ status: 200, }); - this.$emit(event); + let date = new Date(data.ReceivedAt); + let msgId = data.MessageID; + + let id = `${msgId}-${date.toISOString()}`; + + this.$emit(data, { + id, + summary: data.Subject, + ts: date.valueOf(), + }); }, }; From b89f2305fa96c3b1bd57a4b250e2f26ab5db2ba5 Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Wed, 18 May 2022 02:53:03 -0300 Subject: [PATCH 12/19] [App:Postmark] Creating 'common' module for sources --- components/postmark/sources/common.mjs | 27 +++++++++++++++++++ .../new-email-opened/new-email-opened.mjs | 25 +++-------------- .../new-inbound-email-received.mjs | 26 ++---------------- 3 files changed, 32 insertions(+), 46 deletions(-) create mode 100644 components/postmark/sources/common.mjs diff --git a/components/postmark/sources/common.mjs b/components/postmark/sources/common.mjs new file mode 100644 index 0000000000000..91a5a3faf7ec8 --- /dev/null +++ b/components/postmark/sources/common.mjs @@ -0,0 +1,27 @@ +import postmark from "../postmark.app.mjs"; + +export default { + props: { + postmark, + http: { + type: "$.interface.http", + customResponse: true, + }, + }, + async run(data) { + this.http.respond({ + status: 200, + }); + + let date = new Date(data.ReceivedAt); + let msgId = data.MessageID; + + let id = `${msgId}-${date.toISOString()}`; + + this.$emit(data, { + id, + summary: data.Subject, + ts: date.valueOf(), + }); + }, +}; diff --git a/components/postmark/sources/new-email-opened/new-email-opened.mjs b/components/postmark/sources/new-email-opened/new-email-opened.mjs index f09bdf0d05861..298dc587f1c26 100644 --- a/components/postmark/sources/new-email-opened/new-email-opened.mjs +++ b/components/postmark/sources/new-email-opened/new-email-opened.mjs @@ -1,17 +1,14 @@ -import postmark from "../../postmark.app.mjs"; +import common from "../common.mjs"; export default { + ...common, key: "postmark-new-email-opened", name: "New Email Opened", description: "Emit new event when an email is opened by a recipient [(See docs here)](https://postmarkapp.com/developer/webhooks/open-tracking-webhook)", version: "0.0.1", type: "source", props: { - postmark, - http: { - type: "$.interface.http", - customResponse: true, - }, + ...common.props, trackOpensByDefault: { type: "boolean", label: "Track opens by default", @@ -41,20 +38,4 @@ export default { }); }, }, - async run(data) { - this.http.respond({ - status: 200, - }); - - let date = new Date(data.ReceivedAt); - let msgId = data.MessageID; - - let id = `${msgId}-${date.toISOString()}`; - - this.$emit(data, { - id, - summary: data.Subject, - ts: date.valueOf(), - }); - }, }; diff --git a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs index 7180fae82cb6c..752682dd7c07e 100644 --- a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs +++ b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs @@ -1,19 +1,13 @@ -import postmark from "../../postmark.app.mjs"; +import common from "../common.mjs"; export default { + ...common, key: "postmark-new-inbound-email-received", name: "New Inbound Email Received", description: "Emit new event when an email is received by the Postmark server [(See docs here)](https://postmarkapp.com/developer/webhooks/inbound-webhook)", version: "0.0.1", type: "source", - props: { - postmark, - http: { - type: "$.interface.http", - customResponse: true, - }, - }, hooks: { async activate() { return this.postmark.setServerInfo({ @@ -26,20 +20,4 @@ export default { }); }, }, - async run(data) { - this.http.respond({ - status: 200, - }); - - let date = new Date(data.ReceivedAt); - let msgId = data.MessageID; - - let id = `${msgId}-${date.toISOString()}`; - - this.$emit(data, { - id, - summary: data.Subject, - ts: date.valueOf(), - }); - }, }; From a97d243905f67c424378cd34aad02d580a06347b Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Wed, 18 May 2022 22:28:01 -0300 Subject: [PATCH 13/19] [App:Postmark] Finished common module for sources --- components/postmark/sources/common.mjs | 31 ++++++++++++++++--- .../new-email-opened/new-email-opened.mjs | 19 ++++++------ .../new-inbound-email-received.mjs | 14 +++------ 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/components/postmark/sources/common.mjs b/components/postmark/sources/common.mjs index 91a5a3faf7ec8..272d7c21a4def 100644 --- a/components/postmark/sources/common.mjs +++ b/components/postmark/sources/common.mjs @@ -8,20 +8,43 @@ export default { customResponse: true, }, }, + methods: { + getWebhookType() { + throw new Error("Component is missing Webhook type definition"); + }, + getWebhookProps() { + return {}; + }, + }, + hooks: { + async activate() { + return this.postmark.setServerInfo({ + Name: `New Test Name ${Date.now()}`, + [this.getWebhookType()]: this.http.endpoint, + ...this.getWebhookProps(), + }); + }, + async deactivate() { + return this.postmark.setServerInfo({ + [this.getWebhookType()]: "", + }); + }, + }, async run(data) { this.http.respond({ status: 200, }); - let date = new Date(data.ReceivedAt); - let msgId = data.MessageID; + let dateParam = data.ReceivedAt ?? data.Date ?? Date.now(); + let dateObj = new Date(dateParam); - let id = `${msgId}-${date.toISOString()}`; + let msgId = data.MessageID; + let id = `${msgId}-${dateObj.toISOString()}`; this.$emit(data, { id, summary: data.Subject, - ts: date.valueOf(), + ts: dateObj.valueOf(), }); }, }; diff --git a/components/postmark/sources/new-email-opened/new-email-opened.mjs b/components/postmark/sources/new-email-opened/new-email-opened.mjs index 298dc587f1c26..0a220cfe76ae1 100644 --- a/components/postmark/sources/new-email-opened/new-email-opened.mjs +++ b/components/postmark/sources/new-email-opened/new-email-opened.mjs @@ -4,7 +4,8 @@ export default { ...common, key: "postmark-new-email-opened", name: "New Email Opened", - description: "Emit new event when an email is opened by a recipient [(See docs here)](https://postmarkapp.com/developer/webhooks/open-tracking-webhook)", + description: + "Emit new event when an email is opened by a recipient [(See docs here)](https://postmarkapp.com/developer/webhooks/open-tracking-webhook)", version: "0.0.1", type: "source", props: { @@ -24,18 +25,16 @@ export default { Otherwise, the event will be emitted every time an open occurs.`, }, }, - hooks: { - async activate() { - return this.postmark.setServerInfo({ - OpenHookUrl: this.http.endpoint, + methods: { + ...common.methods, + getWebhookProps() { + return { PostFirstOpenOnly: this.postFirstOpenOnly, TrackOpens: this.trackOpensByDefault, - }); + }; }, - async deactivate() { - return this.postmark.setServerInfo({ - OpenHookUrl: "", - }); + getWebhookType() { + return "OpenHookUrl"; }, }, }; diff --git a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs index 752682dd7c07e..ee2af1ef5f3d9 100644 --- a/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs +++ b/components/postmark/sources/new-inbound-email-received/new-inbound-email-received.mjs @@ -8,16 +8,10 @@ export default { "Emit new event when an email is received by the Postmark server [(See docs here)](https://postmarkapp.com/developer/webhooks/inbound-webhook)", version: "0.0.1", type: "source", - hooks: { - async activate() { - return this.postmark.setServerInfo({ - InboundHookUrl: this.http.endpoint, - }); - }, - async deactivate() { - return this.postmark.setServerInfo({ - InboundHookUrl: "", - }); + methods: { + ...common.methods, + getWebhookType() { + return "InboundHookUrl"; }, }, }; From 8247f67d8bb3b28b9ec643a732d6c3fa27cecc8f Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Wed, 18 May 2022 23:39:12 -0300 Subject: [PATCH 14/19] [App:Postmark] Creating 'common' module for actions --- components/postmark/actions/common.mjs | 104 ++++++++++++++++ .../send-email-with-template.mjs | 23 ++-- .../send-single-email/send-single-email.mjs | 25 ++-- components/postmark/postmark.app.mjs | 113 ------------------ components/postmark/sources/common.mjs | 1 - 5 files changed, 118 insertions(+), 148 deletions(-) create mode 100644 components/postmark/actions/common.mjs diff --git a/components/postmark/actions/common.mjs b/components/postmark/actions/common.mjs new file mode 100644 index 0000000000000..acfae21b101a2 --- /dev/null +++ b/components/postmark/actions/common.mjs @@ -0,0 +1,104 @@ +import postmark from "../postmark.app.mjs"; + +export default { + props: { + postmark, + fromEmail: { + type: "string", + label: "\"From\" email address", + description: + "The sender email address. Must have a registered and confirmed Sender Signature. To include a name, use the format 'Full Name <sender@domain.com>' for the address.", + }, + toEmail: { + type: "string", + label: "Recipient email address(es)", + description: + "Recipient email address. Multiple addresses are comma separated. Max 50.", + }, + ccEmail: { + type: "string", + label: "CC email address(es)", + description: + "Cc recipient email address. Multiple addresses are comma separated. Max 50.", + optional: true, + }, + bccEmail: { + type: "string", + label: "BCC email address(es)", + description: + "Bcc recipient email address. Multiple addresses are comma separated. Max 50.", + optional: true, + }, + tag: { + type: "string", + label: "Tag", + description: + "Email tag that allows you to categorize outgoing emails and get detailed statistics.", + optional: true, + }, + replyTo: { + type: "string", + label: "\"Reply To\" email address", + description: + "Reply To override email address. Defaults to the Reply To set in the sender signature.", + optional: true, + }, + customHeaders: { + type: "string[]", + label: "Custom Headers", + description: "List of custom headers to include.", + optional: true, + }, + trackOpens: { + type: "boolean", + label: "Track Opens", + description: "Activate open tracking for this email.", + optional: true, + }, + trackLinks: { + type: "string", + label: "Track Links", + description: + "Activate link tracking for links in the HTML or Text bodies of this email.", + optional: true, + options: [ + "None", + "HtmlAndText", + "HtmlOnly", + "TextOnly", + ], + }, + attachments: { + type: "string[]", + label: "Attachments", + description: `Each attachment should be a string with the parameters separated by a pipe character \`|\`, in the format: \`Name|Content|ContentType\`. Alternatively, you can pass a string representing an object. All three parameters are required: + \\ + \\ + \`Name\` - the filename with extension, i.e. \`readme.txt\` + \\ + \`Content\` - the base64-encoded string with the binary data for the file, i.e. \`dGVzdCBjb250ZW50\` + \\ + \`ContentType\` - the MIME content type, i.e. \`text/plain\` + \\ + \\ + Example with pipe-separated parameters: \`readme.txt|dGVzdCBjb250ZW50|text/plain\` + \\ + Example with JSON-stringified object: \`{"Name":"readme.txt","Content":"dGVzdCBjb250ZW50","ContentType":"text/plain"}\` + `, + optional: true, + }, + metadata: { + type: "object", + label: "Metadata", + description: "Custom metadata key/value pairs.", + optional: true, + }, + messageStream: { + type: "string", + label: "Message stream", + description: + "Set message stream ID that's used for sending. If not provided, message will default to the outbound transactional stream.", + optional: true, + }, + }, +}; diff --git a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs index d198caf75f535..ec2e4252fa8f0 100644 --- a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs +++ b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs @@ -1,49 +1,40 @@ import postmark from "../../postmark.app.mjs"; - -let objSharedProps = {}; -postmark.methods.listSharedProps().forEach((propName) => { - objSharedProps[propName] = { - propDefinition: [ - postmark, - propName, - ], - }; -}); +import common from "../common.mjs"; export default { + ...common, key: "postmark-send-email-with-template", name: "Send Email With Template", description: "Send a single email with Postmark using a template [(See docs here)](https://postmarkapp.com/developer/api/templates-api#email-with-template)", version: "0.0.1", type: "action", props: { - postmark, + ...common.props, templateAlias: { propDefinition: [ postmark, "templateAlias", ], }, - template_model: { + templateModel: { type: "object", label: "Template Model", description: "The model to be applied to the specified template to generate the email body and subject.", }, - inline_css: { + inlineCss: { type: "boolean", label: "Inline CSS", description: "By default, if the specified template contains an HTMLBody, Postmark will apply the style blocks as inline attributes to the rendered HTML content. You may opt-out of this behavior by passing false for this request field.", optional: true, }, - ...objSharedProps, }, async run({ $ }) { return this.postmark.sharedActionRequest($, this, "email/withTemplate", { TemplateAlias: this.templateAlias, - TemplateModel: this.template_model, - InlineCSS: this.inline_css, + TemplateModel: this.templateModel, + InlineCSS: this.inlineCss, }); }, }; diff --git a/components/postmark/actions/send-single-email/send-single-email.mjs b/components/postmark/actions/send-single-email/send-single-email.mjs index d74b20c390723..466fed0716dc5 100644 --- a/components/postmark/actions/send-single-email/send-single-email.mjs +++ b/components/postmark/actions/send-single-email/send-single-email.mjs @@ -1,50 +1,39 @@ -// legacy_hash_id: a_8KiGrJ -import postmark from "../../postmark.app.mjs"; - -let objSharedProps = {}; -postmark.methods.listSharedProps().forEach((propName) => { - objSharedProps[propName] = { - propDefinition: [ - postmark, - propName, - ], - }; -}); +import common from "../common.mjs"; export default { + ...common, key: "postmark-send-single-email", name: "Send Single Email", description: "Send a single email with Postmark [(See docs here)](https://postmarkapp.com/developer/api/email-api#send-a-single-email)", version: "0.2.0", type: "action", props: { - postmark, + ...common.props, subject: { type: "string", label: "Subject", description: "Email subject.", }, - html_body: { + htmlBody: { type: "string", label: "HTML Body", description: "HTML email message. **Required** if no `TextBody` is specified.", optional: true, }, - text_body: { + textBody: { type: "string", label: "Text Body", description: "Plain text email message. **Required** if no `HtmlBody` is specified.", optional: true, }, - ...objSharedProps, }, async run({ $ }) { return this.postmark.sharedActionRequest($, this, "email", { Subject: this.subject, - HtmlBody: this.html_body, - TextBody: this.text_body, + HtmlBody: this.htmlBody, + TextBody: this.textBody, }); }, }; diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index 9f1c64a5f53bd..e9787a736e7f9 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -13,103 +13,6 @@ export default { return this.listTemplates(); }, }, - fromEmail: { - type: "string", - label: "\"From\" email address", - description: - "The sender email address. Must have a registered and confirmed Sender Signature. To include a name, use the format 'Full Name <sender@domain.com>' for the address.", - }, - toEmail: { - type: "string", - label: "Recipient email address(es)", - description: - "Recipient email address. Multiple addresses are comma separated. Max 50.", - }, - ccEmail: { - type: "string", - label: "CC email address(es)", - description: - "Cc recipient email address. Multiple addresses are comma separated. Max 50.", - optional: true, - }, - bccEmail: { - type: "string", - label: "BCC email address(es)", - description: - "Bcc recipient email address. Multiple addresses are comma separated. Max 50.", - optional: true, - }, - tag: { - type: "string", - label: "Tag", - description: - "Email tag that allows you to categorize outgoing emails and get detailed statistics.", - optional: true, - }, - replyTo: { - type: "string", - label: "\"Reply To\" email address", - description: - "Reply To override email address. Defaults to the Reply To set in the sender signature.", - optional: true, - }, - customHeaders: { - type: "string[]", - label: "Custom Headers", - description: "List of custom headers to include.", - optional: true, - }, - trackOpens: { - type: "boolean", - label: "Track Opens", - description: "Activate open tracking for this email.", - optional: true, - }, - trackLinks: { - type: "string", - label: "Track Links", - description: - "Activate link tracking for links in the HTML or Text bodies of this email.", - optional: true, - options: [ - "None", - "HtmlAndText", - "HtmlOnly", - "TextOnly", - ], - }, - attachments: { - type: "string[]", - label: "Attachments", - description: `Each attachment should be a string with the parameters separated by a pipe character \`|\`, in the format: \`Name|Content|ContentType\`. Alternatively, you can pass a string representing an object. All three parameters are required: - \\ - \\ - \`Name\` - the filename with extension, i.e. \`readme.txt\` - \\ - \`Content\` - the base64-encoded string with the binary data for the file, i.e. \`dGVzdCBjb250ZW50\` - \\ - \`ContentType\` - the MIME content type, i.e. \`text/plain\` - \\ - \\ - Example with pipe-separated parameters: \`readme.txt|dGVzdCBjb250ZW50|text/plain\` - \\ - Example with JSON-stringified object: \`{"Name":"readme.txt","Content":"dGVzdCBjb250ZW50","ContentType":"text/plain"}\` - `, - optional: true, - }, - metadata: { - type: "object", - label: "Metadata", - description: "Custom metadata key/value pairs.", - optional: true, - }, - messageStream: { - type: "string", - label: "Message stream", - description: - "Set message stream ID that's used for sending. If not provided, message will default to the outbound transactional stream.", - optional: true, - }, }, methods: { _apikey() { @@ -151,22 +54,6 @@ export default { : JSON.parse(str); }); }, - listSharedProps() { - return [ - "fromEmail", - "toEmail", - "ccEmail", - "bccEmail", - "tag", - "replyTo", - "customHeaders", - "trackOpens", - "trackLinks", - "attachments", - "metadata", - "messageStream", - ]; - }, async sharedActionRequest($, action, endpoint, uniqueProps) { return await axiosPipedream($, { url: `https://api.postmarkapp.com/${endpoint}`, diff --git a/components/postmark/sources/common.mjs b/components/postmark/sources/common.mjs index 272d7c21a4def..d70c8ec001447 100644 --- a/components/postmark/sources/common.mjs +++ b/components/postmark/sources/common.mjs @@ -19,7 +19,6 @@ export default { hooks: { async activate() { return this.postmark.setServerInfo({ - Name: `New Test Name ${Date.now()}`, [this.getWebhookType()]: this.http.endpoint, ...this.getWebhookProps(), }); From 4ab44bbd1a4c5b25f4d1d2fb45e714d65cf73132 Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Thu, 19 May 2022 21:02:36 -0300 Subject: [PATCH 15/19] [App:Postmark] Improving actions' common request data Improved use of pd-axios, and created wrapper methods for requests --- components/postmark/actions/common.mjs | 30 ++++++++++ .../send-email-with-template.mjs | 8 ++- .../send-single-email/send-single-email.mjs | 8 ++- components/postmark/postmark.app.mjs | 60 ++++++------------- 4 files changed, 60 insertions(+), 46 deletions(-) diff --git a/components/postmark/actions/common.mjs b/components/postmark/actions/common.mjs index acfae21b101a2..724d72752fdd5 100644 --- a/components/postmark/actions/common.mjs +++ b/components/postmark/actions/common.mjs @@ -101,4 +101,34 @@ export default { optional: true, }, }, + methods: { + getActionRequestCommonData() { + return { + From: this.fromEmail, + To: this.toEmail, + Cc: this.ccEmail, + Bcc: this.bccEmail, + Tag: this.tag, + ReplyTo: this.replyTo, + Headers: this.customHeaders, + TrackOpens: this.trackOpens, + TrackLinks: this.trackLinks, + Attachments: this.getAttachmentData(this.attachments), + Metadata: this.metadata, + MessageStream: this.messageStream, + }; + }, + getAttachmentData(attachments) { + return attachments?.map((str) => { + let params = str.split("|"); + return params.length === 3 + ? { + Name: params[0], + Content: params[1], + ContentType: params[2], + } + : JSON.parse(str); + }); + }, + }, }; diff --git a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs index ec2e4252fa8f0..74bf534a6aef8 100644 --- a/components/postmark/actions/send-email-with-template/send-email-with-template.mjs +++ b/components/postmark/actions/send-email-with-template/send-email-with-template.mjs @@ -31,10 +31,14 @@ export default { }, }, async run({ $ }) { - return this.postmark.sharedActionRequest($, this, "email/withTemplate", { + const data = { + ...this.getActionRequestCommonData(), TemplateAlias: this.templateAlias, TemplateModel: this.templateModel, InlineCSS: this.inlineCss, - }); + }; + const response = await this.postmark.sendEmailWithTemplate($, data); + $.export("$summary", "Sent email with template successfully"); + return response; }, }; diff --git a/components/postmark/actions/send-single-email/send-single-email.mjs b/components/postmark/actions/send-single-email/send-single-email.mjs index 466fed0716dc5..ad2cf8d1aba3a 100644 --- a/components/postmark/actions/send-single-email/send-single-email.mjs +++ b/components/postmark/actions/send-single-email/send-single-email.mjs @@ -30,10 +30,14 @@ export default { }, }, async run({ $ }) { - return this.postmark.sharedActionRequest($, this, "email", { + const data = { + ...this.getActionRequestCommonData(), Subject: this.subject, HtmlBody: this.htmlBody, TextBody: this.textBody, - }); + }; + const response = await this.postmark.sendSingleEmail($, data); + $.export("$summary", "Sent email successfully"); + return response; }, }; diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index e9787a736e7f9..62cbbf13f5e40 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -1,5 +1,4 @@ -import axios from "axios"; -import { axios as axiosPipedream } from "@pipedream/platform"; +import { axios } from "@pipedream/platform"; export default { type: "app", @@ -18,8 +17,8 @@ export default { _apikey() { return this.$auth.api_key; }, - async listTemplates() { - const { data } = await axios({ + async listTemplates($ = this) { + const data = await axios($, { url: "https://api.postmarkapp.com/templates?Count=500&Offset=0&TemplateType=Standard", headers: this.getHeaders(), method: "GET", @@ -42,50 +41,27 @@ export default { "Accept": "application/json", }; }, - getAttachmentData(attachments) { - return attachments?.map((str) => { - let params = str.split("|"); - return params.length === 3 - ? { - Name: params[0], - Content: params[1], - ContentType: params[2], - } - : JSON.parse(str); - }); - }, - async sharedActionRequest($, action, endpoint, uniqueProps) { - return await axiosPipedream($, { + async sharedActionRequest($, endpoint, data) { + return axios($, { url: `https://api.postmarkapp.com/${endpoint}`, headers: this.getHeaders(), method: "POST", - data: { - ...uniqueProps, - From: action.fromEmail, - To: action.toEmail, - Cc: action.ccEmail, - Bcc: action.bccEmail, - Tag: action.tag, - ReplyTo: action.replyTo, - Headers: action.customHeaders, - TrackOpens: action.trackOpens, - TrackLinks: action.trackLinks, - Attachments: this.getAttachmentData(this.attachments), - Metadata: action.metadata, - MessageStream: action.messageStream, - }, + data, }); }, + async sendSingleEmail($, data) { + return this.sharedActionRequest($, "email", data); + }, + async sendEmailWithTemplate($, data) { + return this.sharedActionRequest($, "email/withTemplate", data); + }, async setServerInfo(params) { - return await axios - .put( - "https://api.postmarkapp.com/server", - params, - { - headers: this.getHeaders(), - }, - ) - .then(({ data }) => data); + return axios(this, { + method: "put", + path: "https://api.postmarkapp.com/server", + params, + headers: this.getHeaders(), + }); }, }, }; From 4fc223d6016f1e694b9abc3fc73df7e512dee4fa Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Thu, 19 May 2022 22:57:15 -0300 Subject: [PATCH 16/19] [App:Postmark] Async options pagination Corrected and standardized some request params as well --- components/postmark/postmark.app.mjs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index 62cbbf13f5e40..87bc6c570faa2 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -8,8 +8,9 @@ export default { type: "string", label: "Template", description: "The template to use for this email.", - async options() { - return this.listTemplates(); + async options(context) { + const { page } = context; + return this.listTemplates(page); }, }, }, @@ -17,11 +18,14 @@ export default { _apikey() { return this.$auth.api_key; }, - async listTemplates($ = this) { - const data = await axios($, { - url: "https://api.postmarkapp.com/templates?Count=500&Offset=0&TemplateType=Standard", - headers: this.getHeaders(), + async listTemplates(page) { + const amountPerPage = 3; + const offset = page * amountPerPage; + + const data = await axios(this, { + url: `https://api.postmarkapp.com/templates?Count=${amountPerPage}&Offset=${offset}&TemplateType=Standard`, method: "GET", + headers: this.getHeaders(), }); return data.TotalCount @@ -44,8 +48,8 @@ export default { async sharedActionRequest($, endpoint, data) { return axios($, { url: `https://api.postmarkapp.com/${endpoint}`, - headers: this.getHeaders(), method: "POST", + headers: this.getHeaders(), data, }); }, @@ -55,12 +59,12 @@ export default { async sendEmailWithTemplate($, data) { return this.sharedActionRequest($, "email/withTemplate", data); }, - async setServerInfo(params) { + async setServerInfo(data) { return axios(this, { + url: "https://api.postmarkapp.com/server", method: "put", - path: "https://api.postmarkapp.com/server", - params, headers: this.getHeaders(), + data, }); }, }, From a6c1e42ff6dda31fd677aaabd425a7848be123db Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Fri, 20 May 2022 14:28:11 -0300 Subject: [PATCH 17/19] [App:Postmark] PR fixes and organizing requests --- components/postmark/postmark.app.mjs | 57 ++++++++++++++++++---------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/components/postmark/postmark.app.mjs b/components/postmark/postmark.app.mjs index 87bc6c570faa2..1b5f63128eb3d 100644 --- a/components/postmark/postmark.app.mjs +++ b/components/postmark/postmark.app.mjs @@ -9,8 +9,22 @@ export default { label: "Template", description: "The template to use for this email.", async options(context) { - const { page } = context; - return this.listTemplates(page); + let { page } = context; + const data = await this.listTemplates(page++); + const options = + data.Templates?.map((obj) => { + return { + label: obj.Name, + value: obj.Alias, + }; + }) ?? []; + + return { + options, + context: { + page, + }, + }; }, }, }, @@ -19,24 +33,13 @@ export default { return this.$auth.api_key; }, async listTemplates(page) { - const amountPerPage = 3; + const amountPerPage = 10; const offset = page * amountPerPage; - const data = await axios(this, { - url: `https://api.postmarkapp.com/templates?Count=${amountPerPage}&Offset=${offset}&TemplateType=Standard`, + return this.sharedRequest(this, { + endpoint: `templates?Count=${amountPerPage}&Offset=${offset}&TemplateType=Standard`, method: "GET", - headers: this.getHeaders(), }); - - return data.TotalCount - ? data.Templates.map((obj) => { - return { - label: obj.Name, - value: obj.Alias, - }; - }) - : []; - }, getHeaders() { return { @@ -45,14 +48,27 @@ export default { "Accept": "application/json", }; }, - async sharedActionRequest($, endpoint, data) { + async sharedRequest($, params) { + const { + endpoint, + method, + data, + } = params; + return axios($, { url: `https://api.postmarkapp.com/${endpoint}`, - method: "POST", + method, headers: this.getHeaders(), data, }); }, + async sharedActionRequest($, endpoint, data) { + return this.sharedRequest($, { + endpoint, + method: "POST", + data, + }); + }, async sendSingleEmail($, data) { return this.sharedActionRequest($, "email", data); }, @@ -60,10 +76,9 @@ export default { return this.sharedActionRequest($, "email/withTemplate", data); }, async setServerInfo(data) { - return axios(this, { - url: "https://api.postmarkapp.com/server", + return this.sharedRequest(this, { + endpoint: "server", method: "put", - headers: this.getHeaders(), data, }); }, From 721cea88a39fcfc929e07533b0575b7b8ab2cee4 Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Mon, 23 May 2022 21:22:19 -0300 Subject: [PATCH 18/19] [App:Postmark] Updating prop descriptions To remind the user of a limitation documented by Postmark --- .../actions/send-single-email/send-single-email.mjs | 13 ++++++++++--- .../sources/new-email-opened/new-email-opened.mjs | 5 +++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/components/postmark/actions/send-single-email/send-single-email.mjs b/components/postmark/actions/send-single-email/send-single-email.mjs index ad2cf8d1aba3a..d62efd7d4c991 100644 --- a/components/postmark/actions/send-single-email/send-single-email.mjs +++ b/components/postmark/actions/send-single-email/send-single-email.mjs @@ -8,7 +8,6 @@ export default { version: "0.2.0", type: "action", props: { - ...common.props, subject: { type: "string", label: "Subject", @@ -18,16 +17,24 @@ export default { type: "string", label: "HTML Body", description: - "HTML email message. **Required** if no `TextBody` is specified.", + `HTML email message. + \\ + **Required** if no \`Text Body\` is specified. + \\ + **Required** to enable \`Open Tracking\`.`, optional: true, }, textBody: { type: "string", label: "Text Body", description: - "Plain text email message. **Required** if no `HtmlBody` is specified.", + `Plain text email message. + \\ + **Required** if no \`HTML Body\` is specified.`, optional: true, }, + // The above props are intentionally placed first + ...common.props, }, async run({ $ }) { const data = { diff --git a/components/postmark/sources/new-email-opened/new-email-opened.mjs b/components/postmark/sources/new-email-opened/new-email-opened.mjs index 0a220cfe76ae1..6f7609043fe5d 100644 --- a/components/postmark/sources/new-email-opened/new-email-opened.mjs +++ b/components/postmark/sources/new-email-opened/new-email-opened.mjs @@ -13,9 +13,10 @@ export default { trackOpensByDefault: { type: "boolean", label: "Track opens by default", - description: `If enabled, all emails being sent through this server will have open tracking enabled. + description: `If enabled, all emails being sent through this server will have open tracking enabled by default. Otherwise, only emails that have open tracking explicitly set will trigger this event when opened. \\ - Otherwise, only emails that have open tracking explicitly set will trigger this event when opened.`, + **Note:** only emails with \`HTML Body\` will have open tracking enabled. + `, }, postFirstOpenOnly: { type: "boolean", From 595a93b973f2f532cd0285fb81975c892f824cc0 Mon Sep 17 00:00:00 2001 From: "guilherme.falcao" Date: Mon, 23 May 2022 21:32:28 -0300 Subject: [PATCH 19/19] [App:Postmark] Updating common TrackOpens prop To further describe the 'html body' vs 'open tracking' relation --- components/postmark/actions/common.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/postmark/actions/common.mjs b/components/postmark/actions/common.mjs index 724d72752fdd5..348f092ef0eae 100644 --- a/components/postmark/actions/common.mjs +++ b/components/postmark/actions/common.mjs @@ -52,7 +52,9 @@ export default { trackOpens: { type: "boolean", label: "Track Opens", - description: "Activate open tracking for this email.", + description: `Activate open tracking for this email. + \\ + **Note:** the email must have \`HTML Body\` to enable open tracking.`, optional: true, }, trackLinks: {