Skip to content

Commit 6213fec

Browse files
committed
updates
1 parent 33d26f3 commit 6213fec

File tree

7 files changed

+167
-45
lines changed

7 files changed

+167
-45
lines changed

components/lusha/actions/company-enrich/company-enrich.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ export default {
44
key: "lusha-company-enrich",
55
name: "Enrich Companies",
66
description: "Enriches company information based on provided company IDs. [See the documentation](https://docs.lusha.com/apis/openapi/company-search-and-enrich/enrichprospectingcompanies)",
7-
//version: "0.0.3",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.3",
98
type: "action",
109
props: {
1110
lusha,

components/lusha/actions/company-search/company-search.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ export default {
55
key: "lusha-company-search",
66
name: "Search Companies",
77
description: "Search for companies using various filters. [See the documentation](https://docs.lusha.com/apis/openapi/company-search-and-enrich/searchprospectingcompanies)",
8-
//version: "0.0.2",
9-
version: "0.0.{{ts}}",
8+
version: "0.0.2",
109
type: "action",
1110
props: {
1211
lusha,
@@ -53,9 +52,10 @@ export default {
5352
],
5453
},
5554
limit: {
56-
type: "string",
57-
label: "Limit",
58-
description: "The maximum number of results to return. **This feature is used to avoid timeouts due to very long returns.**",
55+
propDefinition: [
56+
lusha,
57+
"limit",
58+
],
5959
},
6060
},
6161
async run({ $ }) {

components/lusha/actions/contact-enrich/contact-enrich.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "lusha-contact-enrich",
55
name: "Enrich Contacts",
66
description: "Enriches contacts based on provided IDs. [See the documentation](https://docs.lusha.com/apis/openapi/contact-search-and-enrich/enrichprospectingcontacts)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
lusha,

components/lusha/actions/contact-search/contact-search.mjs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ export default {
55
key: "lusha-contact-search",
66
name: "Search Contacts",
77
description: "Search for contacts using various filters. [See the documentation](https://docs.lusha.com/apis/openapi/contact-search-and-enrich/searchprospectingcontacts)",
8-
//version: "0.0.2",
9-
version: "0.0.{{ts}}",
8+
version: "0.0.2",
109
type: "action",
1110
props: {
1211
lusha,
@@ -60,9 +59,15 @@ export default {
6059
"location",
6160
],
6261
},
62+
limit: {
63+
propDefinition: [
64+
lusha,
65+
"limit",
66+
],
67+
},
6368
},
6469
async run({ $ }) {
65-
/* const include = {};
70+
const include = {};
6671

6772
if (this.names) include.names = parseObject(this.names);
6873
if (this.jobTitles) include.jobTitles = parseObject(this.jobTitles);
@@ -91,29 +96,9 @@ export default {
9196

9297
for await (const item of response) {
9398
responseArray.push(item);
94-
} */
95-
96-
const response = await this.lusha.searchContacts({
97-
$,
98-
data: {
99-
filters: {
100-
contacts: {
101-
include: {
102-
names: parseObject(this.names),
103-
jobTitles: parseObject(this.jobTitles),
104-
jobTitlesExactMatch: parseObject(this.jobTitlesExactMatch),
105-
countries: parseObject(this.countries),
106-
seniority: parseObject(this.seniority),
107-
departments: parseObject(this.departments),
108-
existingDataPoints: parseObject(this.existingDataPoints),
109-
location: parseObject(this.location),
110-
},
111-
},
112-
},
113-
},
114-
});
99+
}
115100

116-
// $.export("$summary", `Found ${responseArray.length} contacts`);
117-
return response;
101+
$.export("$summary", `Found ${responseArray.length} contacts`);
102+
return responseArray;
118103
},
119104
};

components/lusha/actions/search-and-enrich-companies/search-and-enrich-companies.mjs

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import lusha from "../../lusha.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
23

34
export default {
45
key: "lusha-search-and-enrich-companies",
56
name: "Search and Enrich Companies",
67
description: "Search for companies and enrich them. [See the documentation](https://docs.lusha.com/apis/openapi/company-search-and-enrich)",
7-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
89
type: "action",
910
props: {
1011
lusha,
@@ -51,11 +52,69 @@ export default {
5152
],
5253
},
5354
limit: {
54-
type: "string",
55-
label: "Limit",
56-
description: "The maximum number of results to return. **This feature is used to avoid timeouts due to very long returns.**",
55+
propDefinition: [
56+
lusha,
57+
"limit",
58+
],
5759
},
5860
},
59-
async run() {
61+
async run({ $ }) {
62+
const include = {};
63+
64+
if (this.names) include.names = parseObject(this.names);
65+
if (this.domains) include.domains = parseObject(this.domains);
66+
if (this.locations) include.locations = parseObject(this.locations);
67+
if (this.sizes) include.sizes = parseObject(this.sizes);
68+
if (this.revenues) include.revenues = parseObject(this.revenues);
69+
if (this.sicCodes) include.sicCodes = parseObject(this.sicCodes);
70+
if (this.naicsCodes) include.naicsCodes = parseObject(this.naicsCodes);
71+
72+
const companies = [];
73+
let hasMore, count = 0, page = 0;
74+
75+
do {
76+
const {
77+
requestId, data = [],
78+
} = await this.lusha.searchCompanies({
79+
$,
80+
params: {
81+
pages: {
82+
page,
83+
size: 50,
84+
},
85+
},
86+
data: {
87+
filters: {
88+
companies: {
89+
include,
90+
},
91+
},
92+
},
93+
});
94+
hasMore = data.length;
95+
const companyIds = [];
96+
97+
for (const d of data) {
98+
companyIds.push(d.id);
99+
if (++count >= this.limit) {
100+
hasMore = false;
101+
break;
102+
}
103+
}
104+
105+
const enrichedCompanies = await this.lusha.enrichCompanies({
106+
$,
107+
data: {
108+
requestId,
109+
companyIds,
110+
},
111+
});
112+
113+
companies.push(...enrichedCompanies.companies);
114+
page++;
115+
} while (hasMore);
116+
117+
$.export("$summary", `Found and enriched ${companies.length} companies`);
118+
return companies;
60119
},
61120
};

components/lusha/actions/search-and-enrich-contacts/search-and-enrich-contacts.mjs

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import lusha from "../../lusha.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
23

34
export default {
45
key: "lusha-search-and-enrich-contacts",
56
name: "Search and Enrich Contacts",
67
description: "Search for contacts and enrich them. [See the documentation](https://docs.lusha.com/apis/openapi/contact-search-and-enrich)",
7-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
89
type: "action",
910
props: {
1011
lusha,
@@ -58,8 +59,73 @@ export default {
5859
"location",
5960
],
6061
},
62+
limit: {
63+
propDefinition: [
64+
lusha,
65+
"limit",
66+
],
67+
},
6168
},
62-
async run() {
69+
async run({ $ }) {
70+
const include = {};
71+
72+
if (this.names) include.names = parseObject(this.names);
73+
if (this.jobTitles) include.jobTitles = parseObject(this.jobTitles);
74+
if (this.jobTitlesExactMatch)
75+
include.jobTitlesExactMatch = parseObject(this.jobTitlesExactMatch);
76+
if (this.countries) include.countries = parseObject(this.countries);
77+
if (this.seniority) include.seniority = parseObject(this.seniority);
78+
if (this.departments) include.departments = parseObject(this.departments);
79+
if (this.existingDataPoints) include.existingDataPoints = parseObject(this.existingDataPoints);
80+
if (this.location) include.location = parseObject(this.location);
81+
82+
const contacts = [];
83+
let hasMore, count = 0, page = 0;
84+
85+
do {
86+
const {
87+
requestId, data = [],
88+
} = await this.lusha.searchContacts({
89+
$,
90+
params: {
91+
pages: {
92+
page,
93+
size: 50,
94+
},
95+
},
96+
data: {
97+
filters: {
98+
contacts: {
99+
include,
100+
},
101+
},
102+
},
103+
});
104+
105+
hasMore = data.length;
106+
const contactIds = [];
107+
108+
for (const d of data) {
109+
contactIds.push(d.contactId);
110+
if (++count >= this.limit) {
111+
hasMore = false;
112+
break;
113+
}
114+
}
115+
116+
const enrichedContacts = await this.lusha.enrichContacts({
117+
$,
118+
data: {
119+
requestId,
120+
contactIds,
121+
},
122+
});
123+
124+
contacts.push(...enrichedContacts.contacts);
125+
page++;
126+
} while (hasMore);
63127

128+
$.export("$summary", `Found and enriched ${contacts.length} contacts`);
129+
return contacts;
64130
},
65131
};

components/lusha/lusha.app.mjs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default {
5050
async options() {
5151
const sicCodes = await this.listSicCodes();
5252
return sicCodes.map(({
53-
code: value, name: label,
53+
code: value, label,
5454
}) => ({
5555
value,
5656
label,
@@ -65,7 +65,7 @@ export default {
6565
async options() {
6666
const naicsCodes = await this.listNaicsCodes();
6767
return naicsCodes.map(({
68-
code: value, name: label,
68+
code: value, label,
6969
}) => ({
7070
value,
7171
label,
@@ -111,7 +111,13 @@ export default {
111111
description: "Seniority levels of contacts to search",
112112
optional: true,
113113
async options() {
114-
return await this.listSeniorities();
114+
const senorities = await this.listSeniorities();
115+
return senorities.map(({
116+
id: value, name: label,
117+
}) => ({
118+
value,
119+
label,
120+
}));
115121
},
116122
},
117123
departments: {
@@ -153,6 +159,12 @@ export default {
153159
label: "Enrich Company IDs",
154160
description: "Array of company IDs to enrich",
155161
},
162+
limit: {
163+
type: "integer",
164+
label: "Limit",
165+
description: "The maximum number of results to return. **This feature is used to avoid timeouts due to very long returns.**",
166+
default: 50,
167+
},
156168
},
157169
methods: {
158170
_baseUrl() {
@@ -253,11 +265,12 @@ export default {
253265
}) {
254266
let hasMore = false;
255267
let count = 0;
256-
let page = 0;
268+
let page = -1;
257269

258270
do {
259271
params.pages = {
260272
page: ++page,
273+
size: 50,
261274
};
262275
const { data } = await fn({
263276
params,

0 commit comments

Comments
 (0)