|
| 1 | +import { ConfigurationError } from "@pipedream/platform"; |
| 2 | +import { EMAIL_TYPE_OPTIONS } from "../../common/constants.mjs"; |
| 3 | +import prospeo from "../../prospeo.app.mjs"; |
| 4 | + |
| 5 | +export default { |
| 6 | + name: "Search Domain", |
| 7 | + version: "0.0.1", |
| 8 | + key: "prospeo-search-domain", |
| 9 | + description: "Discover email addresses associated with a domain name, website, or company name. [See the documentation](https://prospeo.io/api/domain-search)", |
| 10 | + type: "action", |
| 11 | + props: { |
| 12 | + prospeo, |
| 13 | + company: { |
| 14 | + type: "string", |
| 15 | + label: "Company Domain/Name", |
| 16 | + description: "The company domain, website, or name. Using a domain or website is recommended for better accuracy. If submitting a company name, it needs to be between 3 to 75 characters.", |
| 17 | + }, |
| 18 | + limit: { |
| 19 | + type: "integer", |
| 20 | + label: "Limit", |
| 21 | + description: "How many emails you need. The default value is `50`. You will be charged 1 credit every 50 emails. For example, 35 emails will be charged 1 credit while 65 emails will be charged 2 credits.", |
| 22 | + optional: true, |
| 23 | + }, |
| 24 | + emailType: { |
| 25 | + type: "string", |
| 26 | + label: "Email Type", |
| 27 | + description: "Indicates what type of email you want to get. `generic` refers to role-based emails such as `[email protected]`, while `professional` are emails of people working at the company.", |
| 28 | + options: EMAIL_TYPE_OPTIONS, |
| 29 | + optional: true, |
| 30 | + }, |
| 31 | + companyEnrichment: { |
| 32 | + type: "boolean", |
| 33 | + label: "Company Enrichment", |
| 34 | + description: "Indicates if you want the company details in the response. It is `false` by default. Turning it to `true` might slow-down the response time as we gather the company details.", |
| 35 | + }, |
| 36 | + }, |
| 37 | + async run({ $ }) { |
| 38 | + try { |
| 39 | + const response = await this.prospeo.searchDomain({ |
| 40 | + $, |
| 41 | + data: { |
| 42 | + company: this.company, |
| 43 | + limit: this.limit, |
| 44 | + email_type: this.emailType, |
| 45 | + enrich_company: this.companyEnrichment, |
| 46 | + }, |
| 47 | + }); |
| 48 | + |
| 49 | + $.export("$summary", `Successfully searched domain: ${this.company}`); |
| 50 | + |
| 51 | + return response; |
| 52 | + } catch ({ response }) { |
| 53 | + if (response.data.message === "NO_RESULT") { |
| 54 | + $.export("$summary", `No results found for **${this.company}**`); |
| 55 | + return {}; |
| 56 | + } else { |
| 57 | + throw new ConfigurationError(response.data.message); |
| 58 | + } |
| 59 | + } |
| 60 | + }, |
| 61 | +}; |
0 commit comments