diff --git a/components/lusha/actions/company-enrich/company-enrich.mjs b/components/lusha/actions/company-enrich/company-enrich.mjs index 08794aa0e5c82..9f3c4850708d1 100644 --- a/components/lusha/actions/company-enrich/company-enrich.mjs +++ b/components/lusha/actions/company-enrich/company-enrich.mjs @@ -4,7 +4,7 @@ export default { key: "lusha-company-enrich", name: "Enrich Companies", description: "Enriches company information based on provided company IDs. [See the documentation](https://docs.lusha.com/apis/openapi/company-search-and-enrich/enrichprospectingcompanies)", - version: "0.0.4", + version: "0.0.5", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/lusha/actions/company-search/company-search.mjs b/components/lusha/actions/company-search/company-search.mjs index 4ab514e66d63a..e0c24d25a4f0b 100644 --- a/components/lusha/actions/company-search/company-search.mjs +++ b/components/lusha/actions/company-search/company-search.mjs @@ -5,7 +5,7 @@ export default { key: "lusha-company-search", name: "Search Companies", description: "Search for companies using various filters. [See the documentation](https://docs.lusha.com/apis/openapi/company-search-and-enrich/searchprospectingcompanies)", - version: "0.0.3", + version: "0.0.4", annotations: { destructiveHint: false, openWorldHint: true, @@ -56,49 +56,83 @@ export default { "naicsCodes", ], }, - limit: { - propDefinition: [ - lusha, - "limit", - ], - }, }, async run({ $ }) { - try { - const include = {}; + const { + lusha, + names, + domains, + locations, + sizes, + revenues, + sicCodes, + naicsCodes, + } = this; - 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 include = { + ...(names + ? { + names: parseObject(names), + } + : undefined + ), + ...(domains + ? { + domains: parseObject(domains), + } + : undefined + ), + ...(locations + ? { + locations: parseObject(locations).map((country) => ({ + country, + })), + } + : undefined + ), + ...(sizes + ? { + sizes: parseObject(sizes), + } + : undefined + ), + ...(revenues + ? { + revenues: parseObject(revenues), + } + : undefined + ), + ...(sicCodes + ? { + sicCodes: parseObject(sicCodes), + } + : undefined + ), + ...(naicsCodes + ? { + naicsCodes: parseObject(naicsCodes), + } + : undefined + ), + }; - const response = this.lusha.paginate({ - $, - maxResults: this.limit, - fn: this.lusha.searchCompanies, - data: { - filters: { - companies: { - include, - }, + if (Object.keys(include).length === 0) { + throw new Error("At least one company filter must be provided"); + } + + const response = await lusha.searchCompanies({ + $, + data: { + filters: { + companies: { + include, }, }, - }); + }, + }); - const responseArray = []; + $.export("$summary", "Successfully searched for companies"); - 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; - } + return response; }, }; diff --git a/components/lusha/actions/contact-enrich/contact-enrich.mjs b/components/lusha/actions/contact-enrich/contact-enrich.mjs index ff08da6ff3f14..7c2828559e934 100644 --- a/components/lusha/actions/contact-enrich/contact-enrich.mjs +++ b/components/lusha/actions/contact-enrich/contact-enrich.mjs @@ -4,7 +4,7 @@ export default { key: "lusha-contact-enrich", name: "Enrich Contacts", description: "Enriches contacts based on provided IDs. [See the documentation](https://docs.lusha.com/apis/openapi/contact-search-and-enrich/enrichprospectingcontacts)", - version: "0.0.3", + version: "0.0.4", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/lusha/actions/contact-search/contact-search.mjs b/components/lusha/actions/contact-search/contact-search.mjs index e6222f0d022a8..0ab223a6dc16d 100644 --- a/components/lusha/actions/contact-search/contact-search.mjs +++ b/components/lusha/actions/contact-search/contact-search.mjs @@ -5,7 +5,7 @@ export default { key: "lusha-contact-search", name: "Search Contacts", description: "Search for contacts using various filters. [See the documentation](https://docs.lusha.com/apis/openapi/contact-search-and-enrich/searchprospectingcontacts)", - version: "0.0.3", + version: "0.0.4", annotations: { destructiveHint: false, openWorldHint: true, @@ -82,7 +82,7 @@ export default { 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); + if (this.location) include.locations = parseObject(this.location); const response = this.lusha.paginate({ $, diff --git a/components/lusha/actions/search-and-enrich-companies/search-and-enrich-companies.mjs b/components/lusha/actions/search-and-enrich-companies/search-and-enrich-companies.mjs index 3964414f63295..8eb8e440755c8 100644 --- a/components/lusha/actions/search-and-enrich-companies/search-and-enrich-companies.mjs +++ b/components/lusha/actions/search-and-enrich-companies/search-and-enrich-companies.mjs @@ -5,7 +5,7 @@ export default { key: "lusha-search-and-enrich-companies", name: "Search and Enrich Companies", description: "Search for companies and enrich them. [See the documentation](https://docs.lusha.com/apis/openapi/company-search-and-enrich)", - version: "0.0.2", + version: "0.0.3", annotations: { destructiveHint: false, openWorldHint: true, @@ -64,15 +64,67 @@ export default { }, }, async run({ $ }) { - const include = {}; + const { + lusha, + names, + domains, + locations, + sizes, + revenues, + sicCodes, + naicsCodes, + } = this; - 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 include = { + ...(names + ? { + names: parseObject(names), + } + : undefined + ), + ...(domains + ? { + domains: parseObject(domains), + } + : undefined + ), + ...(locations + ? { + locations: parseObject(locations).map((country) => ({ + country, + })), + } + : undefined + ), + ...(sizes + ? { + sizes: parseObject(sizes), + } + : undefined + ), + ...(revenues + ? { + revenues: parseObject(revenues), + } + : undefined + ), + ...(sicCodes + ? { + sicCodes: parseObject(sicCodes), + } + : undefined + ), + ...(naicsCodes + ? { + naicsCodes: parseObject(naicsCodes), + } + : undefined + ), + }; + + if (Object.keys(include).length === 0) { + throw new Error("At least one company filter must be provided"); + } const companies = []; let hasMore, count = 0, page = 0; @@ -80,7 +132,7 @@ export default { do { const { requestId, data = [], - } = await this.lusha.searchCompanies({ + } = await lusha.searchCompanies({ $, params: { pages: { @@ -97,10 +149,10 @@ export default { }, }); hasMore = data.length; - const companyIds = []; + const companiesIds = []; for (const d of data) { - companyIds.push(d.id); + companiesIds.push(d.id); if (++count >= this.limit) { hasMore = false; break; @@ -111,7 +163,7 @@ export default { $, data: { requestId, - companyIds, + companiesIds, }, }); diff --git a/components/lusha/actions/search-and-enrich-contacts/search-and-enrich-contacts.mjs b/components/lusha/actions/search-and-enrich-contacts/search-and-enrich-contacts.mjs index a1ed92d5b2ad4..bea0c4c17ee82 100644 --- a/components/lusha/actions/search-and-enrich-contacts/search-and-enrich-contacts.mjs +++ b/components/lusha/actions/search-and-enrich-contacts/search-and-enrich-contacts.mjs @@ -5,7 +5,7 @@ export default { key: "lusha-search-and-enrich-contacts", name: "Search and Enrich Contacts", description: "Search for contacts and enrich them. [See the documentation](https://docs.lusha.com/apis/openapi/contact-search-and-enrich)", - version: "0.0.2", + version: "0.0.3", annotations: { destructiveHint: false, openWorldHint: true, @@ -82,7 +82,7 @@ export default { 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); + if (this.location) include.locations = parseObject(this.location); const contacts = []; let hasMore, count = 0, page = 0; diff --git a/components/lusha/lusha.app.mjs b/components/lusha/lusha.app.mjs index c65c7047ab54c..c13cc35859503 100644 --- a/components/lusha/lusha.app.mjs +++ b/components/lusha/lusha.app.mjs @@ -19,7 +19,7 @@ export default { locations: { type: "string[]", label: "Company Locations", - description: "Location filters for companies to search", + description: "Location country filters for companies to search. Eg. `United States`, `Canada`, `United Kingdom`, etc.", optional: true, }, sizes: { @@ -141,7 +141,26 @@ export default { location: { type: "string[]", label: "Contact Locations", - description: "Location filters for contacts to search (JSON strings)", + description: `Location filters for contacts to search. Each entry should be a JSON object with the following optional fields: + +**Available Fields:** +- \`continent\` - The continent name (e.g., "North America") +- \`country\` - The country name (e.g., "United States") +- \`country_grouping\` - Country grouping code (e.g., "na" for North America) +- \`state\` - The state or region name (e.g., "New York") +- \`city\` - The city name (e.g., "New York") + +**Example JSON:** +\`\`\`json +[ + { + "continent": "North America", + "country": "United States", + "state": "New York", + "city": "New York" + } +] +\`\`\``, optional: true, }, requestId: { @@ -261,22 +280,23 @@ export default { }); }, async *paginate({ - fn, params = {}, maxResults = null, ...opts + fn, data = {}, maxResults = null, ...opts }) { let hasMore = false; let count = 0; let page = -1; do { - params.pages = { + data.pages = { page: ++page, size: 50, }; - const { data } = await fn({ - params, + const response = await fn({ + data, ...opts, }); - for (const d of data) { + const results = response.data || []; + for (const d of results) { yield d; if (maxResults && ++count === maxResults) { @@ -284,7 +304,7 @@ export default { } } - hasMore = data.length; + hasMore = results.length; } while (hasMore); }, diff --git a/components/lusha/package.json b/components/lusha/package.json index aad5b4eea784c..748cd11c81376 100644 --- a/components/lusha/package.json +++ b/components/lusha/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/lusha", - "version": "0.2.0", + "version": "0.2.1", "description": "Pipedream Lusha Components", "main": "lusha.app.mjs", "keywords": [