Skip to content

Commit

Permalink
Package Updates, Add Support for Bulk Company Enrichment, Add Size to…
Browse files Browse the repository at this point in the history
… Company Enrichment and Update Types (#164)

* Bump axios from 1.6.2 to 1.6.5

Bumps [axios](https://github.com/axios/axios) from 1.6.2 to 1.6.5.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](axios/axios@v1.6.2...v1.6.5)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* packages

* update package version

* fix tests and upgrade chai

* add new features and tests

* update readme

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: vvillait88 <vvillait88@yahoo.com>
  • Loading branch information
dependabot[bot] and vvillait88 authored Jan 9, 2024
1 parent 68f28b8 commit a44b113
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 147 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,30 @@ try {
console.log(error);
}

// By Bulk Enrichment
const bulkEnrichmentRecords = {
requests: [
{
params: {
profile: ['linkedin.com/in/peopledatalabs'],
},
},
{
params: {
profile: ['linkedin.com/in/apple'],
},
},
],
};

try {
const response = await PDLJSClient.company.bulk.enrichment(bulkEnrichmentRecords);

console.log(response.items);
} catch (error) {
console.log(error);
}

// By Search (SQL)
const sqlQuery = "SELECT * FROM company WHERE tags='big data' AND industry='financial services' AND location.country='united states';"

Expand Down Expand Up @@ -384,6 +408,7 @@ try {
| API Endpoint | PDLJS Function |
|-|-|
| [Company Enrichment API](https://docs.peopledatalabs.com/docs/company-enrichment-api) | `PDLJS.company.enrichment({ ...params })` |
| [Company Bulk Enrichment API](https://docs.peopledatalabs.com/docs/bulk-company-enrichment-api) | `PDLJS.company.bulk.enrichment({ ...records })` |
| [Company Search API](https://docs.peopledatalabs.com/docs/company-search-api) | SQL: `PDLJS.company.search.sql({ ...params })` <br/> Elasticsearch: `PDLJS.company.search.elastic({ ...params })`|

**Supporting Endpoints**
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "peopledatalabs",
"version": "6.2.0",
"version": "7.0.0",
"description": "JavaScript client with TypeScript support for the People Data Labs API",
"type": "module",
"main": "dist/index.cjs",
Expand Down Expand Up @@ -43,15 +43,15 @@
},
"homepage": "https://docs.peopledatalabs.com/docs/javascript-sdk",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"chai": "^4.3.10",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"chai": "^5.0.0",
"dotenv": "^16.3.1",
"eslint": "^8.54.0",
"eslint": "^8.56.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
Expand All @@ -60,10 +60,10 @@
"esm": "^3.2.25",
"microbundle": "^0.15.1",
"mocha": "^10.2.0",
"typescript": "^5.3.2"
"typescript": "^5.3.3"
},
"dependencies": {
"axios": "^1.6.2",
"axios": "^1.6.5",
"copy-anything": "^3.0.5"
}
}
28 changes: 28 additions & 0 deletions src/endpoints/bulkCompanyEnrichment/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import axios from 'axios';

import { check, errorHandler } from '../../errors.js';
import { BulkCompanyEnrichmentParams, BulkCompanyEnrichmentResponse } from '../../types/bulk-types.js';
import { parseRateLimitingResponse } from '../../utils/api-utils.js';

export default (basePath: string, apiKey: string, records: BulkCompanyEnrichmentParams) => {
const headers = {
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip',
'X-Api-Key': apiKey,
'User-Agent': 'PDL-JS-SDK',
};

return new Promise<BulkCompanyEnrichmentResponse>((resolve, reject) => {
check(records, basePath, apiKey, 'Records', 'bulk').then(() => {
axios.post<BulkCompanyEnrichmentResponse>(`${basePath}/company/enrich/bulk`, records, { headers })
.then((response) => {
resolve(parseRateLimitingResponse(response));
})
.catch((error) => {
reject(errorHandler(error));
});
}).catch((error) => {
reject(error);
});
});
};
3 changes: 2 additions & 1 deletion src/endpoints/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import autocomplete from './autocomplete/index.js';
import bulkCompanyEnrichment from './bulkCompanyEnrichment/index.js';
import bulkEnrichment from './bulkEnrichment/index.js';
import bulkRetrieve from './bulkRetrieve/index.js';
import cleaner from './cleaner/index.js';
Expand All @@ -10,4 +11,4 @@ import retrieve from './retrieve/index.js';
import search from './search/index.js';
import skill from './skill/index.js';

export { autocomplete, bulkEnrichment, bulkRetrieve, cleaner, enrichment, enrichmentPreview, identify, jobTitle, retrieve, search, skill };
export { autocomplete, bulkCompanyEnrichment, bulkEnrichment, bulkRetrieve, cleaner, enrichment, enrichmentPreview, identify, jobTitle, retrieve, search, skill };
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { autocomplete, bulkEnrichment, bulkRetrieve, cleaner, enrichment, enrichmentPreview, identify, jobTitle, retrieve, search, skill } from './endpoints/index.js';
import { autocomplete, bulkCompanyEnrichment, bulkEnrichment, bulkRetrieve, cleaner, enrichment, enrichmentPreview, identify, jobTitle, retrieve, search, skill } from './endpoints/index.js';
import ip from './endpoints/ip/index.js';
import { APISettings } from './types/api-types.js';
import { AutoCompleteParams, AutoCompleteResponse } from './types/autocomplete-types.js';
import { BulkPersonRetrieveParams, BulkPersonRetrieveResponse } from './types/bulk-retrieve-types.js';
import { BulkPersonEnrichmentParams, BulkPersonEnrichmentResponse } from './types/bulk-types.js';
import { BulkCompanyEnrichmentParams, BulkCompanyEnrichmentResponse, BulkPersonEnrichmentParams, BulkPersonEnrichmentResponse } from './types/bulk-types.js';
import { CompanyCleanerParams, CompanyCleanerResponse, LocationCleanerParams, LocationCleanerResponse, SchoolCleanerParams, SchoolCleanerResponse } from './types/cleaner-types.js';
import { CompanyResponse, PersonResponse } from './types/common-types.js';
import {
Expand Down Expand Up @@ -51,6 +51,9 @@ class PDLJS {
sql: (params: CompanySearchParams) => Promise<CompanySearchResponse>;
};
cleaner: (params: CompanyCleanerParams) => Promise<CompanyCleanerResponse>;
bulk: {
enrichment: (records: BulkCompanyEnrichmentParams) => Promise<BulkCompanyEnrichmentResponse>;
}
};

public school: { cleaner: (params: SchoolCleanerParams) => Promise<SchoolCleanerResponse> };
Expand Down Expand Up @@ -96,6 +99,9 @@ class PDLJS {
elastic: (params) => search<CompanySearchParams, CompanySearchResponse>(this.basePath, this.sandboxBasePath, this.apiKey, 'elastic', params, 'company'),
sql: (params) => search<CompanySearchParams, CompanySearchResponse>(this.basePath, this.sandboxBasePath, this.apiKey, 'sql', params, 'company'),
},
bulk: {
enrichment: (records) => bulkCompanyEnrichment(this.basePath, this.apiKey, records),
},
cleaner: (params) => cleaner<CompanyCleanerParams, CompanyCleanerResponse>(this.basePath, this.apiKey, params, 'company'),
};

Expand Down Expand Up @@ -123,6 +129,8 @@ export type {
APISettings,
AutoCompleteParams,
AutoCompleteResponse,
BulkCompanyEnrichmentParams,
BulkCompanyEnrichmentResponse,
BulkPersonEnrichmentParams,
BulkPersonEnrichmentResponse,
BulkPersonRetrieveParams,
Expand Down
26 changes: 23 additions & 3 deletions src/types/bulk-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RateLimit } from './api-types.js';
import { PersonEnrichmentParams, PersonEnrichmentResponse } from './enrichment-types.js';
import { CompanyEnrichmentParams, CompanyEnrichmentResponse, PersonEnrichmentParams, PersonEnrichmentResponse } from './enrichment-types.js';

export interface BulkPersonEnrichmentRequest {
params: PersonEnrichmentParams,
Expand All @@ -18,9 +18,29 @@ export interface BulkPersonEnrichmentResponseItem extends PersonEnrichmentRespon
metadata?: unknown
}

// This response does extend from the BaseResponse since each item in the array has its own status
// See https://docs.peopledatalabs.com/docs/bulk-requests
export type BulkPersonEnrichmentResponse = {
items: Array<BulkPersonEnrichmentResponseItem>,
rateLimit: RateLimit
};

export interface BulkCompanyEnrichmentRequest {
params: CompanyEnrichmentParams,
metadata?: unknown // The user can define their own custom metadata
}

export interface BulkCompanyEnrichmentParams {
requests: Array<BulkCompanyEnrichmentRequest> & {
titlecase?: boolean;
include_if_matched?: boolean;
pretty?: boolean;
}
}

export interface BulkCompanyEnrichmentResponseItem extends CompanyEnrichmentResponse {
metadata?: unknown
}

export type BulkCompanyEnrichmentResponse = {
items: Array<BulkCompanyEnrichmentResponseItem>,
rateLimit: RateLimit
};
1 change: 1 addition & 0 deletions src/types/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ export interface CompanyResponse {
size?: string,
employee_count?: number,
id?: string,
linkedin_slug?: string,
founded?: number,
industry?: string,
location?: LocationResponse,
Expand Down
1 change: 1 addition & 0 deletions src/types/enrichment-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface EnrichmentAdditionalParams {
required?: string;
pretty?: boolean;
sandbox?: boolean;
size?: number;
}

/* ---------------------------------------------------------- */
Expand Down
59 changes: 54 additions & 5 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ const autocomplete = {

const company = { name: 'peopledatalabs' };

const companyRecords = {
requests: [
{
params: {
profile: ['linkedin.com/company/peopledatalabs'],
},
},
{
params: {
profile: ['linkedin.com/company/apple'],
},
},
],
};

const location = { location: '455 Market Street, San Francisco, California 94105, US' };

const school = { name: 'university of oregon' };
Expand Down Expand Up @@ -181,7 +196,7 @@ describe('Person Identify', () => {
describe('Person Search', () => {
it(`Should Return Person Records for ${personSQL}`, async () => {
try {
const response = PDLJSClient.person.search.sql({ searchQuery: personSQL, size: 10 });
const response = await PDLJSClient.person.search.sql({ searchQuery: personSQL, size: 10 });

expect(response.status).to.equal(200);
expect(response).to.be.a('object');
Expand All @@ -192,7 +207,7 @@ describe('Person Search', () => {

it('Should Error for Person Search (sql)', async () => {
try {
const response = PDLJSClient.person.search.sql();
const response = await PDLJSClient.person.search.sql();

expect(response.status).to.equal(200);
expect(response).to.be.a('object');
Expand All @@ -203,7 +218,7 @@ describe('Person Search', () => {

it(`Should Return Person Records for ${JSON.stringify(personElastic)}`, async () => {
try {
const response = PDLJSClient.person.search.elastic({ searchQuery: personElastic, size: 10 });
const response = await PDLJSClient.person.search.elastic({ searchQuery: personElastic, size: 10 });

expect(response.status).to.equal(200);
expect(response).to.be.a('object');
Expand All @@ -214,7 +229,7 @@ describe('Person Search', () => {

it('Should Error for Person Search (elastic)', async () => {
try {
const response = PDLJSClient.person.search.elastic();
const response = await PDLJSClient.person.search.elastic();

expect(response.status).to.equal(200);
expect(response).to.be.a('object');
Expand Down Expand Up @@ -253,7 +268,6 @@ describe('Bulk Person Retrieve', () => {
try {
const response = await PDLJSClient.person.bulk.retrieve(bulkRecords);

expect(response.status).to.equal(200);
expect(response).to.be.a('object');
} catch (error) {
expect(error).to.be.a('object');
Expand Down Expand Up @@ -284,6 +298,17 @@ describe('Company Enrichment', () => {
}
});

it('Should Return Multiple Company Records for MRI', async () => {
try {
const response = await PDLJSClient.company.enrichment({ name: 'MRI', size: 2 });

expect(response.status).to.equal(200);
expect(response).to.be.a('object');
} catch (error) {
expect(error).to.be.a('object');
}
});

it('Should Error for Company Enrichment', async () => {
try {
const response = await PDLJSClient.company.enrichment();
Expand All @@ -296,6 +321,30 @@ describe('Company Enrichment', () => {
});
});

describe('Company Bulk Enrichment', () => {
it(`Should Return Company Records for ${JSON.stringify(companyRecords)}`, async () => {
try {
const response = await PDLJSClient.company.bulk.enrichment(companyRecords);

expect(response.items.length).to.equal(2);
expect(response.items).to.be.a('array');
} catch (error) {
expect(error).to.be.a('object');
}
});

it('Should Error for Company Bulk Enrichment', async () => {
try {
const response = await PDLJSClient.company.bulk.enrichment();

expect(response.items.length).to.equal(2);
expect(response.items).to.be.a('array');
} catch (error) {
expect(error).to.be.a('object');
}
});
});

describe('Company Search', () => {
it(`Should Return Company Records for ${companySQL}`, async () => {
try {
Expand Down
Loading

0 comments on commit a44b113

Please sign in to comment.