Skip to content

Commit

Permalink
People Data Labs new action + improvements (PipedreamHQ#11381)
Browse files Browse the repository at this point in the history
* Adding package file

* pnpm

* Search people action

* More props and syntax improvement

* Request improvements

* fixes

* Bugfix
  • Loading branch information
GTFalcao committed Apr 15, 2024
1 parent ae803b9 commit 455e63d
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "people_data_labs-enrich-company",
name: "Enrich a company",
description: "The Company Enrichment API provides a one-to-one match, retrieving up-to-date information on a unique company. [See the docs here](https://docs.peopledatalabs.com/docs/reference-company-enrichment-api)",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
app,
Expand Down Expand Up @@ -104,7 +104,10 @@ export default {
min_likelihood: this.minLikelihood,
};

const res = await this.app.enrichCompany(params);
const res = await this.app.enrichCompany({
$,
params,
});
if (!res) {
$.export("$summary", "No results found");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "people_data_labs-enrich-person",
name: "Enrich a person",
description: "The Person Enrichment API provides a one-to-one match, retrieving up-to-date information on a unique individual. [See the docs here](https://docs.peopledatalabs.com/docs/reference-person-enrichment-api)",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
app,
Expand Down Expand Up @@ -160,7 +160,10 @@ export default {
pretty: this.pretty || true,
};

const res = await this.app.enrichPerson(params);
const res = await this.app.enrichPerson({
$,
params,
});
if (!res) {
$.export("$summary", "No results found");
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { QUERY_TYPE_OPTIONS } from "../../common/constants.mjs";
import app from "../../people_data_labs.app.mjs";

export default {
key: "people_data_labs-search-people",
name: "Search People",
description: "Find specific segments of people that you need to power your projects and products. [See the docs here](https://docs.peopledatalabs.com/docs/reference-person-search-api)",
version: "0.0.1",
type: "action",
props: {
app,
query: {
label: "Query",
type: "string",
description: "The query to perform (can be an [Elasticsearch](https://docs.peopledatalabs.com/docs/input-parameters-person-search-api#query) or [SQL query](https://docs.peopledatalabs.com/docs/input-parameters-person-search-api#sql)). Click the preferred query type for the documentation.",
},
queryType: {
label: "Query Type",
type: "string",
description: "Which type of query is being used.",
options: QUERY_TYPE_OPTIONS,
},
size: {
label: "Size",
type: "integer",
description: "The batch size or the maximum number of matched records to return for this query if they exist",
default: 1,
min: 1,
max: 100,
optional: true,
},
datasets: {
label: "Datasets",
type: "string[]",
description: "Specifies which [dataset(s)](https://docs.peopledatalabs.com/docs/datasets) the API should search against.",
optional: true,
},
titlecase: {
type: "boolean",
label: "Title Case",
description: "By default, all text in the response data returns as lowercase. Setting to `true` will titlecase any records returned.",
optional: true,
},
pretty: {
propDefinition: [
app,
"pretty",
],
},
},
async run({ $ }) {
const {
app, query, queryType, ...data
} = this;
const params = {
[queryType]: query,
...data,
};

const res = await app.searchPeople({
$,
params,
});
$.export("$summary", res?.status === 200
? `Found ${res?.data?.length} records`
: "No records found");
return res;
},
};
45 changes: 45 additions & 0 deletions components/people_data_labs/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export const QUERY_TYPE_OPTIONS = [
{
label: "Elasticsearch query",
value: "query",
},
{
label: "SQL query",
value: "sql",
},
];

export const DATASET_OPTIONS = [
{
label: "All",
value: "all",
},
{
label: "Resume",
value: "resume",
},
{
label: "Email",
value: "email",
},
{
label: "Phone",
value: "phone",
},
{
label: "Mobile Phone",
value: "mobile_phone",
},
{
label: "Street Address",
value: "street_address",
},
{
label: "Consumer Social",
value: "consumer_social",
},
{
label: "Developer",
value: "developer",
},
];
18 changes: 18 additions & 0 deletions components/people_data_labs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@pipedream/people_data_labs",
"version": "0.1.0",
"description": "Pipedream People Data Labs Components",
"main": "people_data_labs.app.mjs",
"keywords": [
"pipedream",
"people_data_labs"
],
"homepage": "https://pipedream.com/apps/people_data_labs",
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.2"
}
}
20 changes: 14 additions & 6 deletions components/people_data_labs/people_data_labs.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export default {
delete res.path;
return res;
},
async _makeRequest(opts = {}) {
async _makeRequest({
$ = this, ...opts
}) {
try {
const axiosParams = this._getAxiosParams(opts);
return await axios(this, axiosParams);
return await axios($, axiosParams);
} catch (err) {
if (err?.response?.data?.error) {
if (err.response.data.error.status == 404) {
Expand All @@ -54,16 +56,22 @@ export default {
}

},
async enrichPerson(params) {
async enrichPerson(args) {
return this._makeRequest({
path: "/person/enrich",
params,
...args,
});
},
async enrichCompany(params) {
async enrichCompany(args) {
return this._makeRequest({
path: "/company/enrich",
params,
...args,
});
},
async searchPeople(args) {
return this._makeRequest({
path: "/person/search",
...args,
});
},
},
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 455e63d

Please sign in to comment.