diff --git a/components/lusha/actions/company-enrich/company-enrich.mjs b/components/lusha/actions/company-enrich/company-enrich.mjs new file mode 100644 index 0000000000000..732e4dadd8422 --- /dev/null +++ b/components/lusha/actions/company-enrich/company-enrich.mjs @@ -0,0 +1,37 @@ +import lusha from "../../lusha.app.mjs"; + +export default { + key: "lusha-company-enrich", + name: "Enrich Companies", + description: "Enriches company information based on provided company IDs. [See the documentation](https://www.lusha.com/docs/#company-enrich)", + version: "0.0.1", + type: "action", + props: { + lusha, + requestId: { + propDefinition: [ + lusha, + "requestId", + ], + label: "Company Request ID", + description: "The request ID generated from the company search response.", + }, + companiesIds: { + propDefinition: [ + lusha, + "companiesIds", + ], + }, + }, + async run({ $ }) { + const response = await this.lusha.enrichCompanies({ + $, + data: { + requestId: this.requestId, + companiesIds: this.companiesIds, + }, + }); + $.export("$summary", `Successfully enriched ${this.companiesIds.length} companies`); + return response; + }, +}; diff --git a/components/lusha/actions/company-search/company-search.mjs b/components/lusha/actions/company-search/company-search.mjs new file mode 100644 index 0000000000000..c00cd4d8b8efa --- /dev/null +++ b/components/lusha/actions/company-search/company-search.mjs @@ -0,0 +1,105 @@ +import { parseObject } from "../../common/utils.mjs"; +import lusha from "../../lusha.app.mjs"; + +export default { + key: "lusha-company-search", + name: "Search Companies", + description: "Search for companies using various filters. [See the documentation](https://www.lusha.com/docs/#contactcompany-search)", + version: "0.0.1", + type: "action", + props: { + lusha, + names: { + propDefinition: [ + lusha, + "companyNames", + ], + optional: true, + }, + domains: { + propDefinition: [ + lusha, + "domains", + ], + optional: true, + }, + locations: { + propDefinition: [ + lusha, + "locations", + ], + optional: true, + }, + sizes: { + propDefinition: [ + lusha, + "sizes", + ], + optional: true, + }, + revenues: { + propDefinition: [ + lusha, + "revenues", + ], + optional: true, + }, + sicCodes: { + propDefinition: [ + lusha, + "sicCodes", + ], + optional: true, + }, + naicsCodes: { + propDefinition: [ + lusha, + "naicsCodes", + ], + optional: true, + }, + limit: { + type: "string", + label: "Limit", + description: "The maximum number of results to return. **This feature is used to avoid timeouts due to very long returns.**", + }, + }, + async run({ $ }) { + try { + const include = {}; + + if (this.names) include.names = parseObject(this.names); + if (this.domains) include.domains = parseObject(this.domains); + if (this.locations) include.locations = parseObject(this.locations); + if (this.sizes) include.sizes = parseObject(this.sizes); + if (this.revenues) include.revenues = parseObject(this.revenues); + if (this.sicCodes) include.sicCodes = parseObject(this.sicCodes); + if (this.naicsCodes) include.naicsCodes = parseObject(this.naicsCodes); + + const response = this.lusha.paginate({ + $, + maxResults: this.limit, + fn: this.lusha.searchCompanies, + data: { + filters: { + companies: { + include, + }, + }, + }, + }); + + const responseArray = []; + + for await (const item of response) { + responseArray.push(item); + } + + $.export("$summary", `Successfully retrieved ${responseArray.length} companies`); + return responseArray; + } catch (error) { + $.export("$summary", "Failed to search companies"); + throw error; + } + }, +}; diff --git a/components/lusha/actions/contact-enrich/contact-enrich.mjs b/components/lusha/actions/contact-enrich/contact-enrich.mjs new file mode 100644 index 0000000000000..732fa6b1f0ff5 --- /dev/null +++ b/components/lusha/actions/contact-enrich/contact-enrich.mjs @@ -0,0 +1,37 @@ +import lusha from "../../lusha.app.mjs"; + +export default { + key: "lusha-contact-enrich", + name: "Enrich Contacts", + description: "Enriches contacts based on provided IDs. [See the documentation](https://www.lusha.com/docs/#contact-enrich)", + version: "0.0.1", + type: "action", + props: { + lusha, + requestId: { + propDefinition: [ + lusha, + "requestId", + ], + label: "Contact Request ID", + description: "The request ID generated from the contact search response.", + }, + contactIds: { + propDefinition: [ + lusha, + "contactIds", + ], + }, + }, + async run({ $ }) { + const response = await this.lusha.enrichContacts({ + $, + data: { + requestId: this.requestId, + contactIds: this.contactIds, + }, + }); + $.export("$summary", `Successfully enriched ${this.contactIds.length} contacts`); + return response; + }, +}; diff --git a/components/lusha/actions/contact-search/contact-search.mjs b/components/lusha/actions/contact-search/contact-search.mjs new file mode 100644 index 0000000000000..d0470eed5b54a --- /dev/null +++ b/components/lusha/actions/contact-search/contact-search.mjs @@ -0,0 +1,98 @@ +import { parseObject } from "../../common/utils.mjs"; +import lusha from "../../lusha.app.mjs"; + +export default { + key: "lusha-contact-search", + name: "Search Contacts", + description: "Search for contacts using various filters. [See the documentation](https://www.lusha.com/docs/#contactcompany-search)", + version: "0.0.1", + type: "action", + props: { + lusha, + names: { + propDefinition: [ + lusha, + "contactNames", + ], + label: "Contact Names", + description: "Names of contacts to search.", + }, + jobTitles: { + propDefinition: [ + lusha, + "jobTitles", + ], + }, + jobTitlesExactMatch: { + propDefinition: [ + lusha, + "jobTitlesExactMatch", + ], + }, + countries: { + propDefinition: [ + lusha, + "countries", + ], + }, + seniority: { + propDefinition: [ + lusha, + "seniority", + ], + }, + departments: { + propDefinition: [ + lusha, + "departments", + ], + }, + existingDataPoints: { + propDefinition: [ + lusha, + "existingDataPoints", + ], + }, + location: { + propDefinition: [ + lusha, + "location", + ], + }, + }, + async run({ $ }) { + const include = {}; + + if (this.names) include.names = parseObject(this.names); + if (this.jobTitles) include.jobTitles = parseObject(this.jobTitles); + if (this.jobTitlesExactMatch) + include.jobTitlesExactMatch = parseObject(this.jobTitlesExactMatch); + if (this.countries) include.countries = parseObject(this.countries); + if (this.seniority) include.seniority = parseObject(this.seniority); + if (this.departments) include.departments = parseObject(this.departments); + if (this.existingDataPoints) include.existingDataPoints = parseObject(this.existingDataPoints); + if (this.location) include.location = parseObject(this.location); + + const response = this.lusha.paginate({ + $, + maxResults: this.limit, + fn: this.lusha.searchContacts, + data: { + filters: { + contacts: { + include, + }, + }, + }, + }); + + const responseArray = []; + + for await (const item of response) { + responseArray.push(item); + } + + $.export("$summary", `Found ${responseArray.length} contacts`); + return response; + }, +}; diff --git a/components/lusha/actions/find-company/find-company.mjs b/components/lusha/actions/find-company/find-company.mjs deleted file mode 100644 index 63f71f7640b78..0000000000000 --- a/components/lusha/actions/find-company/find-company.mjs +++ /dev/null @@ -1,29 +0,0 @@ -import lusha from "../../lusha.app.mjs"; - -export default { - key: "lusha-find-company", - name: "Find Company", - description: "Search for a company. [See docs here](https://www.lusha.com/docs/#company-api)", - version: "0.0.1", - type: "action", - props: { - lusha, - companyName: { - label: "Company Name", - description: "The name of the company", - type: "string", - }, - }, - async run({ $ }) { - const response = this.lusha.findCompany({ - $, - params: { - company: this.companyName, - }, - }); - - $.export("$summary", "Successfully searched company"); - - return response; - }, -}; diff --git a/components/lusha/actions/find-contact/find-contact.mjs b/components/lusha/actions/find-contact/find-contact.mjs deleted file mode 100644 index a0c73a37049d9..0000000000000 --- a/components/lusha/actions/find-contact/find-contact.mjs +++ /dev/null @@ -1,41 +0,0 @@ -import lusha from "../../lusha.app.mjs"; - -export default { - key: "lusha-find-contact", - name: "Find Contact", - description: "Search for a contact. [See docs here](https://www.lusha.com/docs/#person-api)", - version: "0.0.1", - type: "action", - props: { - lusha, - firstName: { - label: "First Name", - description: "The first name of the person", - type: "string", - }, - lastName: { - label: "Last Name", - description: "The last name of the person", - type: "string", - }, - companyName: { - label: "Company Name", - description: "The name of the company", - type: "string", - }, - }, - async run({ $ }) { - const response = this.lusha.findContact({ - $, - params: { - firstName: this.firstName, - lastName: this.lastName, - company: this.companyName, - }, - }); - - $.export("$summary", "Successfully searched contact"); - - return response; - }, -}; diff --git a/components/lusha/common/utils.mjs b/components/lusha/common/utils.mjs new file mode 100644 index 0000000000000..dcc9cc61f6f41 --- /dev/null +++ b/components/lusha/common/utils.mjs @@ -0,0 +1,24 @@ +export const parseObject = (obj) => { + if (!obj) return undefined; + + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + try { + return JSON.parse(item); + } catch (e) { + return item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; diff --git a/components/lusha/lusha.app.mjs b/components/lusha/lusha.app.mjs index a41caa4647d32..5ea955061dc1a 100644 --- a/components/lusha/lusha.app.mjs +++ b/components/lusha/lusha.app.mjs @@ -3,38 +3,170 @@ import { axios } from "@pipedream/platform"; export default { type: "app", app: "lusha", - propDefinitions: {}, - methods: { - _accessToken() { - return this.$auth.oauth_access_token; + propDefinitions: { + companyNames: { + type: "string[]", + label: "Company Names", + description: "Names of companies to search.", + }, + domains: { + type: "string[]", + label: "Company Domains", + description: "Domains of companies to search.", + }, + locations: { + type: "string[]", + label: "Company Locations", + description: "Location filters for companies to search.", + }, + sizes: { + type: "string[]", + label: "Company Sizes", + description: "Size ranges of companies to search.", + }, + revenues: { + type: "string[]", + label: "Company Revenues", + description: "Revenue ranges of companies to search.", + }, + sicCodes: { + type: "string[]", + label: "Company SIC Codes", + description: "SIC codes of companies to search.", + }, + naicsCodes: { + type: "string[]", + label: "Company NAICS Codes", + description: "NAICS codes of companies to search.", + }, + contactNames: { + type: "string[]", + label: "Contact Names", + description: "Names of contacts to search.", + }, + jobTitles: { + type: "string[]", + label: "Contact Job Titles", + description: "Job titles of contacts to search.", + }, + jobTitlesExactMatch: { + type: "string[]", + label: "Exact Match Contact Job Titles", + description: "Exact job titles of contacts to search.", + }, + countries: { + type: "string[]", + label: "Contact Countries", + description: "Country codes of contacts to search.", + }, + seniority: { + type: "integer[]", + label: "Contact Seniority Levels", + description: "Seniority levels of contacts to search.", + }, + departments: { + type: "string[]", + label: "Contact Departments", + description: "Departments of contacts to search.", + }, + existingDataPoints: { + type: "string[]", + label: "Existing Data Points", + description: "Existing data points of contacts to filter by.", + }, + location: { + type: "string[]", + label: "Contact Locations", + description: "Location filters for contacts to search (JSON strings).", }, - _apiUrl() { + requestId: { + type: "string", + label: "Enrich Contact Request ID", + description: "The request ID generated from the contact search response.", + }, + contactIds: { + type: "string[]", + label: "Enrich Contact IDs", + description: "Array of contact IDs to enrich.", + }, + companyIds: { + type: "string[]", + label: "Enrich Company IDs", + description: "Array of company IDs to enrich.", + }, + }, + methods: { + _baseUrl() { return "https://api.lusha.com"; }, - async _makeRequest({ - $ = this, path, ...args - } = {}) { + _headers() { + return { + "api_key": `${this.$auth.api_key}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { return axios($, { - url: `${this._apiUrl()}${path}`, - headers: { - Authorization: `Bearer ${this._accessToken()}`, - }, - ...args, + url: `${this._baseUrl()}${path}`, + headers: this._headers(), + ...opts, + }); + }, + searchContacts(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/prospecting/contact/search", + ...opts, }); }, - async findContact(args = {}) { - const { data } = await this._makeRequest({ - path: "/person", - ...args, + searchCompanies(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/prospecting/company/search", + ...opts, }); - return data; }, - async findCompany(args = {}) { - const { data } = await this._makeRequest({ - path: "/company", - ...args, + enrichContacts(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/prospecting/contact/enrich", + ...opts, }); - return data; + }, + enrichCompanies(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/prospecting/company/enrich", + ...opts, + }); + }, + async *paginate({ + fn, params = {}, maxResults = null, ...opts + }) { + let hasMore = false; + let count = 0; + let page = 0; + + do { + params.pages = { + page: ++page, + }; + const { data } = await fn({ + params, + ...opts, + }); + for (const d of data) { + yield d; + + if (maxResults && ++count === maxResults) { + return count; + } + } + + hasMore = data.length; + + } while (hasMore); }, }, }; diff --git a/components/lusha/package.json b/components/lusha/package.json index c419eb7947c3b..5337866e327f2 100644 --- a/components/lusha/package.json +++ b/components/lusha/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/lusha", - "version": "0.0.3", + "version": "0.1.0", "description": "Pipedream Lusha Components", "main": "lusha.app.mjs", "keywords": [ @@ -14,6 +14,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^0.10.0" + "@pipedream/platform": "^3.0.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39ba56f95f156..ce0af209f0bc2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5948,8 +5948,8 @@ importers: components/lusha: dependencies: '@pipedream/platform': - specifier: ^0.10.0 - version: 0.10.0 + specifier: ^3.0.3 + version: 3.0.3 components/maestra: dependencies: @@ -24525,22 +24525,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - deprecated: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731) + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net supports-color@2.0.0: resolution: {integrity: sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==}