Skip to content

Commit 0f2347b

Browse files
authored
New Components - zerobounce (#14648)
* init * new components * pnpm-lock.yaml * fix prop description * validate fileId * remove console.log
1 parent 3440c62 commit 0f2347b

File tree

9 files changed

+328
-20
lines changed

9 files changed

+328
-20
lines changed

components/zerobounce/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import zerobounce from "../../zerobounce.app.mjs";
2+
3+
export default {
4+
key: "zerobounce-ai-scoring",
5+
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/#single_email_scoring)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
zerobounce,
11+
email: {
12+
type: "string",
13+
label: "Email",
14+
description: "The email address that you want to retrieve Scoring data for",
15+
},
16+
},
17+
async run({ $ }) {
18+
const response = await this.zerobounce.getReliabilityScore({
19+
$,
20+
params: {
21+
email: this.email,
22+
},
23+
});
24+
$.export("$summary", `Successfully estimated reliability score for email: ${this.email}`);
25+
return response;
26+
},
27+
};
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import zerobounce from "../../zerobounce.app.mjs";
2+
import fs from "fs";
3+
import FormData from "form-data";
4+
import path from "path";
5+
6+
export default {
7+
key: "zerobounce-file-validation",
8+
name: "Validate Emails in File",
9+
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/)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
zerobounce,
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+
},
66+
},
67+
async run({ $ }) {
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);
126+
return response;
127+
},
128+
};
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import zerobounce from "../../zerobounce.app.mjs";
2+
import fs from "fs";
3+
import { ConfigurationError } from "@pipedream/platform";
4+
5+
export default {
6+
key: "zerobounce-get-validation-results-file",
7+
name: "Get Validation Results File",
8+
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__)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
zerobounce,
13+
fileId: {
14+
type: "string",
15+
label: "File ID",
16+
description: "The file_id returned when sending the file for validation. Can be found on your Zerobounce \"Validate\" tab under Results next to each filename. Click on the ID circle.",
17+
},
18+
fileName: {
19+
type: "string",
20+
label: "File Name",
21+
description: "The filename to save the file as in the \"/tmp\" directory",
22+
},
23+
},
24+
methods: {
25+
getResultsFile({
26+
$, ...opts
27+
}) {
28+
return this.zerobounce.getResultsFile({
29+
$,
30+
params: {
31+
file_id: this.fileId,
32+
},
33+
...opts,
34+
});
35+
},
36+
async validateFileId({ $ }) {
37+
try {
38+
return await this.getResultsFile({
39+
$,
40+
});
41+
} catch {
42+
throw new ConfigurationError("File not found. Make sure the File ID is correct");
43+
}
44+
},
45+
},
46+
async run({ $ }) {
47+
if (!(await this.validateFileId({
48+
$,
49+
}))) {
50+
return;
51+
}
52+
const response = await this.getResultsFile({
53+
$,
54+
responseType: "arraybuffer",
55+
});
56+
57+
const filePath = `/tmp/${this.fileName}`;
58+
fs.writeFileSync(filePath, response);
59+
60+
$.export("$summary", `File saved to ${filePath}`);
61+
62+
return filePath;
63+
},
64+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import zerobounce from "../../zerobounce.app.mjs";
2+
3+
export default {
4+
key: "zerobounce-validate-email",
5+
name: "Validate Email",
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",
8+
type: "action",
9+
props: {
10+
zerobounce,
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+
},
28+
},
29+
async run({ $ }) {
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+
});
38+
$.export("$summary", `Successfully validated email: ${this.email}`);
39+
return response;
40+
},
41+
};

components/zerobounce/app/zerobounce.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

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 <support@pipedream.com> (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
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "zerobounce",
6+
methods: {
7+
_baseUrl() {
8+
return "https://api.zerobounce.net/v2";
9+
},
10+
_makeRequest(opts = {}) {
11+
const {
12+
$ = this,
13+
path,
14+
url,
15+
params,
16+
...otherOpts
17+
} = opts;
18+
return axios($, {
19+
...otherOpts,
20+
url: url || `${this._baseUrl()}${path}`,
21+
params: {
22+
...params,
23+
api_key: this.$auth.api_key,
24+
},
25+
});
26+
},
27+
validateEmail(opts = {}) {
28+
return this._makeRequest({
29+
path: "/validate",
30+
...opts,
31+
});
32+
},
33+
getReliabilityScore(opts = {}) {
34+
return this._makeRequest({
35+
path: "/scoring",
36+
...opts,
37+
});
38+
},
39+
validateEmailsInFile(opts = {}) {
40+
return this._makeRequest({
41+
method: "POST",
42+
url: "https://bulkapi.zerobounce.net/v2/sendfile",
43+
...opts,
44+
});
45+
},
46+
getResultsFile(opts = {}) {
47+
return this._makeRequest({
48+
url: "https://bulkapi.zerobounce.net/v2/getfile",
49+
...opts,
50+
});
51+
},
52+
},
53+
};

pnpm-lock.yaml

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)