Skip to content

Commit 65d44b6

Browse files
committed
new components
1 parent 92687ba commit 65d44b6

File tree

6 files changed

+222
-45
lines changed

6 files changed

+222
-45
lines changed

components/zerobounce/actions/ai-scoring/ai-scoring.mjs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@ import zerobounce from "../../zerobounce.app.mjs";
33
export default {
44
key: "zerobounce-ai-scoring",
55
name: "AI Scoring",
6-
description: "Estimates a reliability score based on ZeroBounce's AI for the provided email. [See the documentation](https://www.zerobounce.net/docs/ai-scoring-api/)",
7-
version: "0.0.{{ts}}",
6+
description: "Estimates a reliability score based on ZeroBounce's AI for the provided email. [See the documentation](https://www.zerobounce.net/docs/ai-scoring-api/#single_email_scoring)",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
zerobounce,
11-
email: zerobounce.propDefinitions.email,
11+
email: {
12+
type: "string",
13+
label: "Email",
14+
description: "The email address that you want to retrieve Scoring data for",
15+
},
1216
},
1317
async run({ $ }) {
14-
const response = await this.zerobounce.getReliabilityScore(this.email);
18+
const response = await this.zerobounce.getReliabilityScore({
19+
$,
20+
params: {
21+
email: this.email,
22+
},
23+
});
1524
$.export("$summary", `Successfully estimated reliability score for email: ${this.email}`);
1625
return response;
1726
},
Lines changed: 114 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,128 @@
11
import zerobounce from "../../zerobounce.app.mjs";
2+
import fs from "fs";
3+
import FormData from "form-data";
4+
import path from "path";
25

36
export default {
47
key: "zerobounce-file-validation",
58
name: "Validate Emails in File",
69
description: "Performs email validation on all the addresses contained in a provided file. [See the documentation](https://www.zerobounce.net/docs/email-validation-api-quickstart/)",
7-
version: "0.0.{{ts}}",
10+
version: "0.0.1",
811
type: "action",
912
props: {
1013
zerobounce,
11-
file: zerobounce.propDefinitions.file,
14+
filePath: {
15+
type: "string",
16+
label: "File Path",
17+
description: "The path to a csv or txt file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
18+
},
19+
emailAddressColumn: {
20+
type: "integer",
21+
label: "Email Address Column",
22+
description: "The column index of the email address in the file. Index starts from 1.",
23+
},
24+
firstNameColumn: {
25+
type: "integer",
26+
label: "First Name Column",
27+
description: "The column index of the first name column. Index starts from 1.",
28+
optional: true,
29+
},
30+
lastNameColumn: {
31+
type: "integer",
32+
label: "Last Name Column",
33+
description: "The column index of the last name column. Index starts from 1.",
34+
optional: true,
35+
},
36+
ipAddressColumn: {
37+
type: "integer",
38+
label: "IP Address Column",
39+
description: "The IP Address the email signed up from. Index starts from 1",
40+
optional: true,
41+
},
42+
hasHeaderRow: {
43+
type: "boolean",
44+
label: "Has Header Row",
45+
description: "If the first row from the submitted file is a header row",
46+
optional: true,
47+
},
48+
removeDuplicates: {
49+
type: "boolean",
50+
label: "Remove Duplicates",
51+
description: "If you want the system to remove duplicate emails. Default is `true`. Please note that if we remove more than 50% of the lines because of duplicates (parameter is true), system will return a 400 bad request error as a safety net to let you know that more than 50% of the file has been modified.",
52+
optional: true,
53+
},
54+
returnUrl: {
55+
type: "string",
56+
label: "Return URL",
57+
description: "The URL will be used to call back when the validation is completed",
58+
optional: true,
59+
},
60+
callbackWithRerun: {
61+
type: "boolean",
62+
label: "Callback With Rerun",
63+
description: "Use the `$.flow.rerun` Node.js helper to rerun the step when the validation is completed. Overrides the `rerunUrl` prop. This will increase execution time and credit usage as a result. [See the documentation(https://pipedream.com/docs/code/nodejs/rerun/#flow-rerun)",
64+
optional: true,
65+
},
1266
},
1367
async run({ $ }) {
14-
const response = await this.zerobounce.validateEmailsInFile(this.file);
15-
$.export("$summary", "Successfully validated emails in file");
68+
let response, summary;
69+
const { run } = $.context;
70+
71+
if (run.runs === 1) {
72+
let returnUrl = this.returnUrl;
73+
if (this.callbackWithRerun) {
74+
({ resume_url: returnUrl } = $.flow.rerun(600000, null, 1));
75+
}
76+
77+
const filePath = this.filePath.includes("tmp/")
78+
? this.filePath
79+
: `/tmp/${this.filePath}`;
80+
const fileName = path.basename(filePath);
81+
const fileContent = fs.readFileSync(filePath);
82+
83+
const formData = new FormData();
84+
formData.append("file", fileContent, fileName);
85+
formData.append("email_address_column", this.emailAddressColumn);
86+
formData.append("api_key", this.zerobounce.$auth.api_key);
87+
if (this.firstNameColumn) {
88+
formData.append("first_name_column", this.firstNameColumn);
89+
}
90+
if (this.lastNameColumn) {
91+
formData.append("last_name_column", this.lastNameColumn);
92+
}
93+
if (this.ipAddressColumn) {
94+
formData.append("ip_address_column", this.ipAddressColumn);
95+
}
96+
if (this.hasHeaderRow) {
97+
formData.append("has_header_row", this.hasHeaderRow
98+
? "true"
99+
: "false");
100+
}
101+
if (this.removeDuplicates) {
102+
formData.append("remove_duplicate", this.removeDuplicates
103+
? "true"
104+
: "false");
105+
}
106+
if (returnUrl) {
107+
formData.append("return_url", returnUrl);
108+
}
109+
110+
response = await this.zerobounce.validateEmailsInFile({
111+
$,
112+
data: formData,
113+
headers: {
114+
...formData.getHeaders(),
115+
},
116+
});
117+
summary = "Successfully sent file for validation";
118+
}
119+
120+
if (run.callback_request) {
121+
response = run.callback_request.body;
122+
summary = "Successfully validated emails in file";
123+
}
124+
125+
$.export("$summary", summary);
16126
return response;
17127
},
18128
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import zerobounce from "../../zerobounce.app.mjs";
2+
import fs from "fs";
3+
4+
export default {
5+
key: "zerobounce-get-validation-results-file",
6+
name: "Get Validation Results File",
7+
description: "Downloads the validation results for a file submitted using sendfile API. [See the documentation](https://www.zerobounce.net/docs/email-validation-api-quickstart/#get_file__v2__)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
zerobounce,
12+
fileId: {
13+
type: "string",
14+
label: "File ID",
15+
description: "The file_id returned when sending the file for validation",
16+
},
17+
fileName: {
18+
type: "string",
19+
label: "File Name",
20+
description: "The filename to save the file as in the \"/tmp\" directory",
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.zerobounce.getResultsFile({
25+
$,
26+
params: {
27+
file_id: this.fileId,
28+
},
29+
responseType: "arraybuffer",
30+
});
31+
32+
const filePath = `/tmp/${this.fileName}`;
33+
fs.writeFileSync(filePath, response);
34+
35+
$.export("$summary", `File saved to ${filePath}`);
36+
37+
return filePath;
38+
},
39+
};

components/zerobounce/actions/validate-email/validate-email.mjs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,38 @@ import zerobounce from "../../zerobounce.app.mjs";
33
export default {
44
key: "zerobounce-validate-email",
55
name: "Validate Email",
6-
description: "Validates a specific email. [See the documentation](https://www.zerobounce.net/docs/email-validation-api-quickstart/)",
7-
version: "0.0.{{ts}}",
6+
description: "Validates a specific email. [See the documentation](https://www.zerobounce.net/docs/email-validation-api-quickstart/#validate_emails__v2__)",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
zerobounce,
11-
email: zerobounce.propDefinitions.email,
11+
email: {
12+
type: "string",
13+
label: "Email",
14+
description: "The email address to be validated",
15+
},
16+
ipAddress: {
17+
type: "string",
18+
label: "IP Address",
19+
description: "The IP Address the email signed up from",
20+
optional: true,
21+
},
22+
activityData: {
23+
type: "boolean",
24+
label: "Activity Data",
25+
description: "If set to `true`, Activity Data information will be appended to the validation result",
26+
optional: true,
27+
},
1228
},
1329
async run({ $ }) {
14-
const response = await this.zerobounce.validateEmail(this.email);
30+
const response = await this.zerobounce.validateEmail({
31+
$,
32+
params: {
33+
email: this.email,
34+
ip_address: this.ipAddress || "",
35+
activity_data: this.activityData,
36+
},
37+
});
1538
$.export("$summary", `Successfully validated email: ${this.email}`);
1639
return response;
1740
},

components/zerobounce/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
{
22
"name": "@pipedream/zerobounce",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream ZeroBounce Components",
5-
"main": "dist/app/zerobounce.app.mjs",
5+
"main": "zerobounce.app.mjs",
66
"keywords": [
77
"pipedream",
88
"zerobounce"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/zerobounce",
1211
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3",
17+
"form-data": "^4.0.1",
18+
"path": "^0.12.7"
1519
}
1620
}

components/zerobounce/zerobounce.app.mjs

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,50 @@ import { axios } from "@pipedream/platform";
33
export default {
44
type: "app",
55
app: "zerobounce",
6-
propDefinitions: {
7-
email: {
8-
type: "string",
9-
label: "Email",
10-
description: "The email address to be validated",
11-
},
12-
file: {
13-
type: "string",
14-
label: "File",
15-
description: "The file that contains email addresses to be validated",
16-
},
17-
},
186
methods: {
197
_baseUrl() {
208
return "https://api.zerobounce.net/v2";
219
},
22-
async _makeRequest(opts = {}) {
10+
_makeRequest(opts = {}) {
2311
const {
2412
$ = this,
25-
method = "GET",
2613
path,
27-
headers,
14+
url,
15+
params,
2816
...otherOpts
2917
} = opts;
3018
return axios($, {
3119
...otherOpts,
32-
method,
33-
url: this._baseUrl() + path,
34-
headers: {
35-
...headers,
36-
"user-agent": "@PipedreamHQ/pipedream v0.1",
37-
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
20+
url: url || `${this._baseUrl()}${path}`,
21+
params: {
22+
...params,
23+
api_key: this.$auth.api_key,
3824
},
3925
});
4026
},
41-
async validateEmail(email) {
27+
validateEmail(opts = {}) {
4228
return this._makeRequest({
43-
path: `/validate?email=${email}`,
29+
path: "/validate",
30+
...opts,
4431
});
4532
},
46-
async validateEmailsInFile(file) {
33+
getReliabilityScore(opts = {}) {
34+
return this._makeRequest({
35+
path: "/scoring",
36+
...opts,
37+
});
38+
},
39+
validateEmailsInFile(opts = {}) {
4740
return this._makeRequest({
4841
method: "POST",
49-
path: "/sendfile",
50-
data: {
51-
file: file,
52-
},
42+
url: "https://bulkapi.zerobounce.net/v2/sendfile",
43+
...opts,
5344
});
5445
},
55-
async getReliabilityScore(email) {
46+
getResultsFile(opts = {}) {
5647
return this._makeRequest({
57-
path: `/score?email=${email}`,
48+
url: "https://bulkapi.zerobounce.net/v2/getfile",
49+
...opts,
5850
});
5951
},
6052
},

0 commit comments

Comments
 (0)