Skip to content

Commit

Permalink
update headers
Browse files Browse the repository at this point in the history
  • Loading branch information
vvillait88 committed Jul 20, 2022
1 parent d8da93d commit df3a8d4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@ dist
.rts2_cache_cjs
.rts2_cache_es
.rts2_cache_umd

# VS Code
.vscode
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "peopledatalabs",
"version": "3.1.2",
"version": "3.1.5",
"description": "JavaScript client with TypeScript support for the People Data Labs API",
"type": "module",
"main": "dist/index.cjs",
Expand Down
16 changes: 9 additions & 7 deletions src/types/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ export interface APISettings {
}

export interface RateLimit {
retryAfter: number;
rateLimit: number;
rateLimitReset: number;
totalLimit?: number;
totalLimitRemaining?: number;
searchLimitRemaining?: number;
enrichCompanyLimitRemaining?: number;
rateLimitRemaining?: string;
rateLimitReset?: string;
rateLimit?: string;
totalLimitOveragesRemaining?: string;
totalLimitPurchasedRemaining?: string;
totalLimitRemaining?: string;
callCreditsType?: string;
callCreditsSpent?: string;
lifetimeUsed?: string;
}

export interface BaseResponse {
Expand Down
16 changes: 9 additions & 7 deletions src/utils/api-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { RateLimit } from '../types/api-types';
// eslint-disable-next-line import/prefer-default-export
export const parseRateLimitingResponse = (response: AxiosResponse) => {
const rateLimit = {
retryAfter: Number(response.headers['retry-after']) || undefined,
rateLimit: Number(response.headers['x-ratelimit-limit']) || undefined,
rateLimitReset: Number(response.headers['x-ratelimit-reset']) || undefined,
totalLimit: Number(response.headers['x-totallimit-limit']) || undefined,
totalLimitRemaining: Number(response.headers['x-totallimit-remaining']) || undefined,
searchLimitRemaining: Number(response.headers['x-searchlimit-remaining']) || undefined,
enrichCompanyLimitRemaining: Number(response.headers['x-enrichcompanylimit-remaining']) || undefined,
rateLimitRemaining: response.headers['x-ratelimit-remaining'] || undefined,
rateLimitReset: response.headers['x-ratelimit-reset'] || undefined,
rateLimit: response.headers['x-ratelimit-limit'] || undefined,
totalLimitOveragesRemaining: response.headers['x-totallimit-overages-remaining'] || undefined,
totalLimitPurchasedRemaining: response.headers['x-totallimit-purchased-remaining'] || undefined,
totalLimitRemaining: response.headers['x-totallimit-remaining'] || undefined,
callCreditsType: response.headers['x-call-credits-type'] || undefined,
callCreditsSpent: response.headers['x-call-credits-spent'] || undefined,
lifetimeUsed: response.headers['x-lifetime-used'] || undefined,
} as RateLimit;

if (Array.isArray(response.data)) {
Expand Down

0 comments on commit df3a8d4

Please sign in to comment.