Skip to content

Commit

Permalink
add missing types, update readme and version (#22)
Browse files Browse the repository at this point in the history
* add missing types, update readme and version

* remove github push

* more cleanup and better errors

* update examples

* update version
  • Loading branch information
vvillait88 authored Apr 30, 2022
1 parent dbca907 commit 3374f45
Show file tree
Hide file tree
Showing 12 changed files with 3,857 additions and 3,803 deletions.
2 changes: 1 addition & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PDL_API_KEY=
PDL_API_KEY=...
17 changes: 1 addition & 16 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Packages to NPM and Github
name: Publish Package to NPM

on:
release:
Expand Down Expand Up @@ -30,18 +30,3 @@ jobs:
- run: yarn run pub
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

publish-gpr:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
always-auth: true
node-version: 16
registry-url: https://npm.pkg.github.com/
- run: yarn
- run: yarn run pub
env:
NODE_AUTH_TOKEN: ${{secrets.GH_TOKEN}}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<p align="center">
<img src="https://i.imgur.com/S7DkZtr.png" width="250" alt="People Data Labs Logo">
</p>
<h1 align="center">People Data Labs JS Library</h1>
<h1 align="center">People Data Labs JavaScript Library</h1>
<p align="center">
A tiny, universal JS client for the People Data Labs API.
JavaScript client with TypeScript support for the People Data Labs API.
</p>

<p align="center">
Expand Down Expand Up @@ -120,7 +120,7 @@ PDLJSClient.person.search.elastic({ searchQuery: esQuery, size: 10 }).then((data
});

// By PDL_ID
PDLJSClient.person.retrieve('qEnOZ5Oh0poWnQ1luFBfVw_0000').then((data) => {
PDLJSClient.person.retrieve({ id: 'qEnOZ5Oh0poWnQ1luFBfVw_0000' }).then((data) => {
console.log(data);
}).catch((error) => {
console.log(error);
Expand Down
2 changes: 1 addition & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ PDLJSClient.person.search.sql({ searchQuery: "SELECT * FROM person WHERE locatio
console.log(error);
});

PDLJSClient.person.retrieve('qEnOZ5Oh0poWnQ1luFBfVw_0000').then((data) => {
PDLJSClient.person.retrieve({ id: 'qEnOZ5Oh0poWnQ1luFBfVw_0000' }).then((data) => {
console.log(data);
}).catch((error) => {
console.log(error);
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "peopledatalabs",
"version": "2.0.2",
"description": "An universal client for the People Data Labs API",
"version": "3.0.0",
"description": "JavaScript client with TypeScript support for the People Data Labs API",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.m.js",
Expand Down Expand Up @@ -30,7 +30,7 @@
"javascript",
"api",
"client",
"universal"
"sdk"
],
"author": "People Data Labs",
"license": "MIT",
Expand All @@ -43,7 +43,7 @@
"@typescript-eslint/parser": "^5.16.0",
"chai": "^4.3.6",
"dotenv": "^16.0.0",
"eslint": "^8.11.0",
"eslint": "^8.14.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^16.1.4",
Expand Down
11 changes: 5 additions & 6 deletions src/endpoints/retrieve/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import axios from 'axios';
import { check, errorHandler } from '../../errors';
import { RetrieveResponse } from '../../types/retrieve-types';
import { RetrieveParams, RetrieveResponse } from '../../types/retrieve-types';
import { parseRateLimitingResponse } from '../../utils/api-utils';

export default (
basePath: string,
apiKey: string,
id: string,
pretty?: boolean,
params: RetrieveParams,
) => new Promise<RetrieveResponse>((resolve, reject) => {
check(id, basePath, apiKey, 'ID', 'retrieve').then(() => {
check(params.id, basePath, apiKey, 'ID', 'retrieve').then(() => {
const headers = {
'Accept-Encoding': 'gzip',
};

axios.get<RetrieveResponse>(`${basePath}/person/retrieve/${id}`, {
axios.get<RetrieveResponse>(`${basePath}/person/retrieve/${params.id}`, {
params: {
api_key: apiKey,
pretty: pretty || false,
...params,
},
headers,
})
Expand Down
14 changes: 10 additions & 4 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ const errorHandler = (error: AxiosError) => {
500: 'The server encountered an unexpected condition which prevented it from fulfilling the request',
};

// @ts-ignore
return (`${status} Error: ${errorMessages[status >= 500 && status < 600 ? 500 : status]}`);
return ({
status: status >= 500 && status < 600 ? 500 : status,
// eslint-disable-next-line max-len
message: errorMessages[status >= 500 && status < 600 ? 500 : status as keyof typeof errorMessages],
});
}
// @ts-ignore
return (`Error: ${error.toJSON().message}`);

return ({
status: 500,
message: error.message,
});
};

export { check, errorHandler };
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from './types/search-types';
import { IdentifyParams, IdentifyResponse } from './types/identify-types';
import { APISettings } from './types/api-types';
import { RetrieveResponse } from './types/retrieve-types';
import { RetrieveParams, RetrieveResponse } from './types/retrieve-types';

class PDLJS {
private readonly apiKey: string;
Expand All @@ -37,7 +37,7 @@ class PDLJS {
search: { elastic: (params: PersonSearchParams) => Promise<PersonSearchResponse>;
sql: (params: PersonSearchParams) => Promise<PersonSearchResponse> };
identify: (params: IdentifyParams) => Promise<IdentifyResponse>;
retrieve: (id: string, pretty: boolean) => Promise<RetrieveResponse>;
retrieve: (params: RetrieveParams) => Promise<RetrieveResponse>;
bulk: (records: BulkPersonEnrichmentParams) => Promise<BulkPersonEnrichmentResponse>
};

Expand Down Expand Up @@ -70,7 +70,7 @@ class PDLJS {
},
bulk: (records) => bulk(this.basePath, this.apiKey, records),
identify: (params) => identify(this.basePath, this.apiKey, params),
retrieve: (id, pretty) => retrieve(this.basePath, this.apiKey, id, pretty),
retrieve: (params) => retrieve(this.basePath, this.apiKey, params),
};

this.company = {
Expand Down
Loading

0 comments on commit 3374f45

Please sign in to comment.