Skip to content

Commit bd60b98

Browse files
authored
[FIX] Lusha API Authentication Issue (#18889)
1 parent 6dbdde6 commit bd60b98

File tree

8 files changed

+171
-65
lines changed

8 files changed

+171
-65
lines changed

components/lusha/actions/company-enrich/company-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-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.4",
7+
version: "0.0.5",
88
annotations: {
99
destructiveHint: false,
1010
openWorldHint: true,

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

Lines changed: 71 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +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.3",
8+
version: "0.0.4",
99
annotations: {
1010
destructiveHint: false,
1111
openWorldHint: true,
@@ -56,49 +56,83 @@ export default {
5656
"naicsCodes",
5757
],
5858
},
59-
limit: {
60-
propDefinition: [
61-
lusha,
62-
"limit",
63-
],
64-
},
6559
},
6660
async run({ $ }) {
67-
try {
68-
const include = {};
61+
const {
62+
lusha,
63+
names,
64+
domains,
65+
locations,
66+
sizes,
67+
revenues,
68+
sicCodes,
69+
naicsCodes,
70+
} = this;
6971

70-
if (this.names) include.names = parseObject(this.names);
71-
if (this.domains) include.domains = parseObject(this.domains);
72-
if (this.locations) include.locations = parseObject(this.locations);
73-
if (this.sizes) include.sizes = parseObject(this.sizes);
74-
if (this.revenues) include.revenues = parseObject(this.revenues);
75-
if (this.sicCodes) include.sicCodes = parseObject(this.sicCodes);
76-
if (this.naicsCodes) include.naicsCodes = parseObject(this.naicsCodes);
72+
const include = {
73+
...(names
74+
? {
75+
names: parseObject(names),
76+
}
77+
: undefined
78+
),
79+
...(domains
80+
? {
81+
domains: parseObject(domains),
82+
}
83+
: undefined
84+
),
85+
...(locations
86+
? {
87+
locations: parseObject(locations).map((country) => ({
88+
country,
89+
})),
90+
}
91+
: undefined
92+
),
93+
...(sizes
94+
? {
95+
sizes: parseObject(sizes),
96+
}
97+
: undefined
98+
),
99+
...(revenues
100+
? {
101+
revenues: parseObject(revenues),
102+
}
103+
: undefined
104+
),
105+
...(sicCodes
106+
? {
107+
sicCodes: parseObject(sicCodes),
108+
}
109+
: undefined
110+
),
111+
...(naicsCodes
112+
? {
113+
naicsCodes: parseObject(naicsCodes),
114+
}
115+
: undefined
116+
),
117+
};
77118

78-
const response = this.lusha.paginate({
79-
$,
80-
maxResults: this.limit,
81-
fn: this.lusha.searchCompanies,
82-
data: {
83-
filters: {
84-
companies: {
85-
include,
86-
},
119+
if (Object.keys(include).length === 0) {
120+
throw new Error("At least one company filter must be provided");
121+
}
122+
123+
const response = await lusha.searchCompanies({
124+
$,
125+
data: {
126+
filters: {
127+
companies: {
128+
include,
87129
},
88130
},
89-
});
131+
},
132+
});
90133

91-
const responseArray = [];
134+
$.export("$summary", "Successfully searched for companies");
92135

93-
for await (const item of response) {
94-
responseArray.push(item);
95-
}
96-
97-
$.export("$summary", `Successfully retrieved ${responseArray.length} companies`);
98-
return responseArray;
99-
} catch (error) {
100-
$.export("$summary", "Failed to search companies");
101-
throw error;
102-
}
136+
return response;
103137
},
104138
};

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.3",
7+
version: "0.0.4",
88
annotations: {
99
destructiveHint: false,
1010
openWorldHint: true,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +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.3",
8+
version: "0.0.4",
99
annotations: {
1010
destructiveHint: false,
1111
openWorldHint: true,
@@ -82,7 +82,7 @@ export default {
8282
if (this.seniority) include.seniority = parseObject(this.seniority);
8383
if (this.departments) include.departments = parseObject(this.departments);
8484
if (this.existingDataPoints) include.existingDataPoints = parseObject(this.existingDataPoints);
85-
if (this.location) include.location = parseObject(this.location);
85+
if (this.location) include.locations = parseObject(this.location);
8686

8787
const response = this.lusha.paginate({
8888
$,

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

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "lusha-search-and-enrich-companies",
66
name: "Search and Enrich Companies",
77
description: "Search for companies and enrich them. [See the documentation](https://docs.lusha.com/apis/openapi/company-search-and-enrich)",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
annotations: {
1010
destructiveHint: false,
1111
openWorldHint: true,
@@ -64,23 +64,75 @@ export default {
6464
},
6565
},
6666
async run({ $ }) {
67-
const include = {};
67+
const {
68+
lusha,
69+
names,
70+
domains,
71+
locations,
72+
sizes,
73+
revenues,
74+
sicCodes,
75+
naicsCodes,
76+
} = this;
6877

69-
if (this.names) include.names = parseObject(this.names);
70-
if (this.domains) include.domains = parseObject(this.domains);
71-
if (this.locations) include.locations = parseObject(this.locations);
72-
if (this.sizes) include.sizes = parseObject(this.sizes);
73-
if (this.revenues) include.revenues = parseObject(this.revenues);
74-
if (this.sicCodes) include.sicCodes = parseObject(this.sicCodes);
75-
if (this.naicsCodes) include.naicsCodes = parseObject(this.naicsCodes);
78+
const include = {
79+
...(names
80+
? {
81+
names: parseObject(names),
82+
}
83+
: undefined
84+
),
85+
...(domains
86+
? {
87+
domains: parseObject(domains),
88+
}
89+
: undefined
90+
),
91+
...(locations
92+
? {
93+
locations: parseObject(locations).map((country) => ({
94+
country,
95+
})),
96+
}
97+
: undefined
98+
),
99+
...(sizes
100+
? {
101+
sizes: parseObject(sizes),
102+
}
103+
: undefined
104+
),
105+
...(revenues
106+
? {
107+
revenues: parseObject(revenues),
108+
}
109+
: undefined
110+
),
111+
...(sicCodes
112+
? {
113+
sicCodes: parseObject(sicCodes),
114+
}
115+
: undefined
116+
),
117+
...(naicsCodes
118+
? {
119+
naicsCodes: parseObject(naicsCodes),
120+
}
121+
: undefined
122+
),
123+
};
124+
125+
if (Object.keys(include).length === 0) {
126+
throw new Error("At least one company filter must be provided");
127+
}
76128

77129
const companies = [];
78130
let hasMore, count = 0, page = 0;
79131

80132
do {
81133
const {
82134
requestId, data = [],
83-
} = await this.lusha.searchCompanies({
135+
} = await lusha.searchCompanies({
84136
$,
85137
params: {
86138
pages: {
@@ -97,10 +149,10 @@ export default {
97149
},
98150
});
99151
hasMore = data.length;
100-
const companyIds = [];
152+
const companiesIds = [];
101153

102154
for (const d of data) {
103-
companyIds.push(d.id);
155+
companiesIds.push(d.id);
104156
if (++count >= this.limit) {
105157
hasMore = false;
106158
break;
@@ -111,7 +163,7 @@ export default {
111163
$,
112164
data: {
113165
requestId,
114-
companyIds,
166+
companiesIds,
115167
},
116168
});
117169

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "lusha-search-and-enrich-contacts",
66
name: "Search and Enrich Contacts",
77
description: "Search for contacts and enrich them. [See the documentation](https://docs.lusha.com/apis/openapi/contact-search-and-enrich)",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
annotations: {
1010
destructiveHint: false,
1111
openWorldHint: true,
@@ -82,7 +82,7 @@ export default {
8282
if (this.seniority) include.seniority = parseObject(this.seniority);
8383
if (this.departments) include.departments = parseObject(this.departments);
8484
if (this.existingDataPoints) include.existingDataPoints = parseObject(this.existingDataPoints);
85-
if (this.location) include.location = parseObject(this.location);
85+
if (this.location) include.locations = parseObject(this.location);
8686

8787
const contacts = [];
8888
let hasMore, count = 0, page = 0;

components/lusha/lusha.app.mjs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
locations: {
2020
type: "string[]",
2121
label: "Company Locations",
22-
description: "Location filters for companies to search",
22+
description: "Location country filters for companies to search. Eg. `United States`, `Canada`, `United Kingdom`, etc.",
2323
optional: true,
2424
},
2525
sizes: {
@@ -141,7 +141,26 @@ export default {
141141
location: {
142142
type: "string[]",
143143
label: "Contact Locations",
144-
description: "Location filters for contacts to search (JSON strings)",
144+
description: `Location filters for contacts to search. Each entry should be a JSON object with the following optional fields:
145+
146+
**Available Fields:**
147+
- \`continent\` - The continent name (e.g., "North America")
148+
- \`country\` - The country name (e.g., "United States")
149+
- \`country_grouping\` - Country grouping code (e.g., "na" for North America)
150+
- \`state\` - The state or region name (e.g., "New York")
151+
- \`city\` - The city name (e.g., "New York")
152+
153+
**Example JSON:**
154+
\`\`\`json
155+
[
156+
{
157+
"continent": "North America",
158+
"country": "United States",
159+
"state": "New York",
160+
"city": "New York"
161+
}
162+
]
163+
\`\`\``,
145164
optional: true,
146165
},
147166
requestId: {
@@ -261,30 +280,31 @@ export default {
261280
});
262281
},
263282
async *paginate({
264-
fn, params = {}, maxResults = null, ...opts
283+
fn, data = {}, maxResults = null, ...opts
265284
}) {
266285
let hasMore = false;
267286
let count = 0;
268287
let page = -1;
269288

270289
do {
271-
params.pages = {
290+
data.pages = {
272291
page: ++page,
273292
size: 50,
274293
};
275-
const { data } = await fn({
276-
params,
294+
const response = await fn({
295+
data,
277296
...opts,
278297
});
279-
for (const d of data) {
298+
const results = response.data || [];
299+
for (const d of results) {
280300
yield d;
281301

282302
if (maxResults && ++count === maxResults) {
283303
return count;
284304
}
285305
}
286306

287-
hasMore = data.length;
307+
hasMore = results.length;
288308

289309
} while (hasMore);
290310
},

components/lusha/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/lusha",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Pipedream Lusha Components",
55
"main": "lusha.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)