Skip to content

Commit 86dc611

Browse files
committed
improve description and validate from & replyTo props
1 parent 016d67b commit 86dc611

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

components/elastic_email/actions/create-campaign/create-campaign.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import app from "../../elastic_email.app.mjs";
22
import { ConfigurationError } from "@pipedream/platform";
3+
import { isValidEmailFormat } from "../../common/utils.mjs";
34

45
export default {
56
key: "elastic_email-create-campaign",
@@ -22,7 +23,7 @@ export default {
2223
from: {
2324
type: "string",
2425
label: "From",
25-
description: "Your e-mail with an optional name (e.g.: John Doe email@domain.com)",
26+
description: "Your e-mail with an optional name (e.g.: `email@domain.com` or `John Doe <email@domain.com>`)",
2627
},
2728
recipientListNames: {
2829
propDefinition: [
@@ -44,7 +45,7 @@ export default {
4445
replyTo: {
4546
type: "string",
4647
label: "Reply To",
47-
description: "To what address should the recipients reply to (e.g. John Doe email@domain.com)",
48+
description: "To what address should the recipients reply to (e.g. `email@domain.com` or `John Doe <email@domain.com>`)",
4849
},
4950
status: {
5051
propDefinition: [
@@ -84,6 +85,13 @@ export default {
8485
},
8586
},
8687
async run({ $ }) {
88+
if (this.from && !isValidEmailFormat(this.from)) {
89+
throw new ConfigurationError("Invalid email format for 'From'");
90+
}
91+
if (this.replyTo && !isValidEmailFormat(this.replyTo)) {
92+
throw new ConfigurationError("Invalid email format for 'Reply To'");
93+
}
94+
8795
if (!this.recipientListNames && !this.recipientSegmentNames) {
8896
throw new ConfigurationError("You must provide at least one list or segment to read recipients from");
8997
}

components/elastic_email/actions/send-email/send-email.mjs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import {
22
BODY_CONTENT_TYPE_OPTIONS,
33
ENCODING_OPTIONS,
44
} from "../../common/constants.mjs";
5-
import { parseObject } from "../../common/utils.mjs";
5+
import {
6+
parseObject, isValidEmailFormat,
7+
} from "../../common/utils.mjs";
8+
import { ConfigurationError } from "@pipedream/platform";
69
import app from "../../elastic_email.app.mjs";
710

811
export default {
@@ -26,7 +29,7 @@ export default {
2629
from: {
2730
type: "string",
2831
label: "From",
29-
description: "Your e-mail with an optional name (e.g.: email@domain.com)",
32+
description: "Your e-mail with an optional name (e.g.: `email@domain.com` or `John Doe <email@domain.com>`)",
3033
},
3134
bodyContentType: {
3235
type: "string",
@@ -50,7 +53,7 @@ export default {
5053
replyTo: {
5154
type: "string",
5255
label: "Reply To",
53-
description: "To what address should the recipients reply to (e.g. email@domain.com)",
56+
description: "To what address should the recipients reply to (e.g. `email@domain.com` or `John Doe <email@domain.com>`)",
5457
optional: true,
5558
},
5659
subject: {
@@ -105,6 +108,13 @@ export default {
105108
},
106109
},
107110
async run({ $ }) {
111+
if (this.from && !isValidEmailFormat(this.from)) {
112+
throw new ConfigurationError("Invalid email format for 'From'");
113+
}
114+
if (this.replyTo && !isValidEmailFormat(this.replyTo)) {
115+
throw new ConfigurationError("Invalid email format for 'Reply To'");
116+
}
117+
108118
const response = await this.app.sendBulkEmails({
109119
$,
110120
data: {

components/elastic_email/actions/update-campaign/update-campaign.mjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import app from "../../elastic_email.app.mjs";
2+
import { isValidEmailFormat } from "../../common/utils.mjs";
3+
import { ConfigurationError } from "@pipedream/platform";
24

35
export default {
46
key: "elastic_email-update-campaign",
@@ -28,7 +30,7 @@ export default {
2830
from: {
2931
type: "string",
3032
label: "From",
31-
description: "Your e-mail with an optional name (e.g.: John Doe email@domain.com)",
33+
description: "Your e-mail with an optional name (e.g.: `email@domain.com` or `John Doe <email@domain.com>`)",
3234
optional: true,
3335
},
3436
recipientListNames: {
@@ -51,7 +53,7 @@ export default {
5153
replyTo: {
5254
type: "string",
5355
label: "Reply To",
54-
description: "To what address should the recipients reply to (e.g. John Doe email@domain.com)",
56+
description: "To what address should the recipients reply to (e.g. `email@domain.com` or `John Doe <email@domain.com>`)",
5557
optional: true,
5658
},
5759
subject: {
@@ -93,6 +95,13 @@ export default {
9395
},
9496
},
9597
async run({ $ }) {
98+
if (this.from && !isValidEmailFormat(this.from)) {
99+
throw new ConfigurationError("Invalid email format for 'From'");
100+
}
101+
if (this.replyTo && !isValidEmailFormat(this.replyTo)) {
102+
throw new ConfigurationError("Invalid email format for 'Reply To'");
103+
}
104+
96105
const campaign = await this.app.getCampaign({
97106
$,
98107
campaign: this.campaign,

components/elastic_email/common/utils.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const parseObject = (obj) => {
1+
const parseObject = (obj) => {
22
if (!obj) return undefined;
33

44
if (Array.isArray(obj)) {
@@ -22,3 +22,13 @@ export const parseObject = (obj) => {
2222
}
2323
return obj;
2424
};
25+
26+
const isValidEmailFormat = (str) => {
27+
const emailPattern = /^(?:[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}|[^<>]+<\s*[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\s*>)$/;
28+
return emailPattern.test(str.trim());
29+
};
30+
31+
export {
32+
parseObject,
33+
isValidEmailFormat,
34+
};

0 commit comments

Comments
 (0)