kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: minor improvements to clearbit, diffbot, perigon, and proxycurl
rodzic
94a4c7763f
commit
fa0628f8ca
|
@ -2,7 +2,13 @@ import defaultKy from 'ky'
|
||||||
import pThrottle from 'p-throttle'
|
import pThrottle from 'p-throttle'
|
||||||
|
|
||||||
import type { DeepNullable, KyInstance } from '../types.js'
|
import type { DeepNullable, KyInstance } from '../types.js'
|
||||||
import { assert, delay, getEnv, throttleKy } from '../utils.js'
|
import {
|
||||||
|
assert,
|
||||||
|
delay,
|
||||||
|
getEnv,
|
||||||
|
sanitizeSearchParams,
|
||||||
|
throttleKy
|
||||||
|
} from '../utils.js'
|
||||||
|
|
||||||
export namespace clearbit {
|
export namespace clearbit {
|
||||||
// Allow up to 600 requests per minute by default.
|
// Allow up to 600 requests per minute by default.
|
||||||
|
@ -11,6 +17,8 @@ export namespace clearbit {
|
||||||
interval: 60 * 1000
|
interval: 60 * 1000
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const MAX_PAGE_SIZE = 100
|
||||||
|
|
||||||
export interface CompanyEnrichmentOptions {
|
export interface CompanyEnrichmentOptions {
|
||||||
domain: string
|
domain: string
|
||||||
webhook_url?: string
|
webhook_url?: string
|
||||||
|
@ -358,19 +366,8 @@ export namespace clearbit {
|
||||||
role: string
|
role: string
|
||||||
seniority: string
|
seniority: string
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
export const PersonRoles = [
|
||||||
* The Clearbit API helps with resolving and enriching people and company data.
|
|
||||||
*
|
|
||||||
* @see https://dashboard.clearbit.com/docs
|
|
||||||
*/
|
|
||||||
export class ClearbitClient {
|
|
||||||
protected readonly ky: KyInstance
|
|
||||||
protected readonly apiKey: string
|
|
||||||
protected readonly _maxPageSize = 100
|
|
||||||
|
|
||||||
static readonly PersonRoles = [
|
|
||||||
'communications',
|
'communications',
|
||||||
'customer_service',
|
'customer_service',
|
||||||
'education',
|
'education',
|
||||||
|
@ -391,7 +388,7 @@ export class ClearbitClient {
|
||||||
'sales'
|
'sales'
|
||||||
]
|
]
|
||||||
|
|
||||||
static readonly SenioritiesV2 = [
|
export const SenioritiesV2 = [
|
||||||
'Executive',
|
'Executive',
|
||||||
'VP',
|
'VP',
|
||||||
'Owner',
|
'Owner',
|
||||||
|
@ -402,9 +399,9 @@ export class ClearbitClient {
|
||||||
'Entry'
|
'Entry'
|
||||||
]
|
]
|
||||||
|
|
||||||
static readonly Seniorities = ['executive', 'director', 'manager']
|
export const Seniorities = ['executive', 'director', 'manager']
|
||||||
|
|
||||||
static readonly SubIndustries = [
|
export const SubIndustries = [
|
||||||
'Automotive',
|
'Automotive',
|
||||||
'Consumer Discretionary',
|
'Consumer Discretionary',
|
||||||
'Consumer Goods',
|
'Consumer Goods',
|
||||||
|
@ -516,6 +513,16 @@ export class ClearbitClient {
|
||||||
'Energy',
|
'Energy',
|
||||||
'Utilities'
|
'Utilities'
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Clearbit API helps with resolving and enriching people and company data.
|
||||||
|
*
|
||||||
|
* @see https://dashboard.clearbit.com/docs
|
||||||
|
*/
|
||||||
|
export class ClearbitClient {
|
||||||
|
protected readonly ky: KyInstance
|
||||||
|
protected readonly apiKey: string
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
apiKey = getEnv('CLEARBIT_API_KEY'),
|
apiKey = getEnv('CLEARBIT_API_KEY'),
|
||||||
|
@ -573,14 +580,13 @@ export class ClearbitClient {
|
||||||
async prospectorPeopleV2(options: clearbit.PeopleSearchOptionsV2) {
|
async prospectorPeopleV2(options: clearbit.PeopleSearchOptionsV2) {
|
||||||
return this.ky
|
return this.ky
|
||||||
.get('https://prospector.clearbit.com/v2/people/search', {
|
.get('https://prospector.clearbit.com/v2/people/search', {
|
||||||
// @ts-expect-error location is a string[] and searchparams shows a TS error heres
|
searchParams: sanitizeSearchParams({
|
||||||
searchParams: {
|
|
||||||
...options,
|
...options,
|
||||||
page_size: Math.min(
|
page_size: Math.min(
|
||||||
this._maxPageSize,
|
clearbit.MAX_PAGE_SIZE,
|
||||||
options.page_size || this._maxPageSize
|
options.page_size || clearbit.MAX_PAGE_SIZE
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
.json<clearbit.ProspectorResponseV2>()
|
.json<clearbit.ProspectorResponseV2>()
|
||||||
}
|
}
|
||||||
|
@ -588,15 +594,14 @@ export class ClearbitClient {
|
||||||
async prospectorPeopleV1(options: clearbit.PeopleSearchOptionsV1) {
|
async prospectorPeopleV1(options: clearbit.PeopleSearchOptionsV1) {
|
||||||
return this.ky
|
return this.ky
|
||||||
.get('https://prospector.clearbit.com/v1/people/search', {
|
.get('https://prospector.clearbit.com/v1/people/search', {
|
||||||
// @ts-expect-error location is a string[] and searchparams shows a TS error heres
|
searchParams: sanitizeSearchParams({
|
||||||
searchParams: {
|
|
||||||
email: false,
|
email: false,
|
||||||
...options,
|
...options,
|
||||||
page_size: Math.min(
|
page_size: Math.min(
|
||||||
this._maxPageSize,
|
clearbit.MAX_PAGE_SIZE,
|
||||||
options.page_size || this._maxPageSize
|
options.page_size || clearbit.MAX_PAGE_SIZE
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
.json<clearbit.ProspectorResponseV1>()
|
.json<clearbit.ProspectorResponseV1>()
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,7 +286,7 @@ export namespace diffbot {
|
||||||
.optional()
|
.optional()
|
||||||
.describe('Name of the entity'),
|
.describe('Name of the entity'),
|
||||||
url: z
|
url: z
|
||||||
.array(z.string())
|
.union([z.string(), z.array(z.string())])
|
||||||
.optional()
|
.optional()
|
||||||
.describe('Origin or homepage URL of the entity'),
|
.describe('Origin or homepage URL of the entity'),
|
||||||
phone: z.string().optional().describe('Phone number of the entity'),
|
phone: z.string().optional().describe('Phone number of the entity'),
|
||||||
|
|
|
@ -168,7 +168,7 @@ export namespace perigon {
|
||||||
'Labels to filter by, could be "Opinion", "Paid-news", "Non-news", etc. If multiple parameters are passed, they will be applied as OR operations.'
|
'Labels to filter by, could be "Opinion", "Paid-news", "Non-news", etc. If multiple parameters are passed, they will be applied as OR operations.'
|
||||||
),
|
),
|
||||||
excludeLabel: z
|
excludeLabel: z
|
||||||
.union([ArticleLabelSchema, z.literal('Low Content')])
|
.array(z.union([ArticleLabelSchema, z.literal('Low Content')]))
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
'Exclude results that include specific labels ("Opinion", "Non-news", "Paid News", etc.). You can filter multiple by repeating the parameter.'
|
'Exclude results that include specific labels ("Opinion", "Non-news", "Paid News", etc.). You can filter multiple by repeating the parameter.'
|
||||||
|
@ -681,19 +681,20 @@ export class PerigonClient extends AIFunctionsProvider {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
async searchArticles(opts: perigon.ArticlesSearchOptions) {
|
async searchArticles(opts: perigon.ArticlesSearchOptions) {
|
||||||
return this.ky
|
const searchParams = sanitizeSearchParams({
|
||||||
.get('all', {
|
sortBy: 'relevance',
|
||||||
searchParams: sanitizeSearchParams({
|
|
||||||
...opts,
|
...opts,
|
||||||
apiKey: this.apiKey,
|
apiKey: this.apiKey,
|
||||||
size: Math.max(
|
size: Math.max(
|
||||||
1,
|
1,
|
||||||
Math.min(
|
Math.min(perigon.MAX_PAGE_SIZE, opts.size || perigon.DEFAULT_PAGE_SIZE)
|
||||||
perigon.MAX_PAGE_SIZE,
|
|
||||||
opts.size || perigon.DEFAULT_PAGE_SIZE
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
console.log('perigon.searchArticles', searchParams)
|
||||||
|
|
||||||
|
return this.ky
|
||||||
|
.get('all', {
|
||||||
|
searchParams
|
||||||
})
|
})
|
||||||
.json<perigon.ArticlesSearchResponse>()
|
.json<perigon.ArticlesSearchResponse>()
|
||||||
}
|
}
|
||||||
|
@ -720,19 +721,20 @@ export class PerigonClient extends AIFunctionsProvider {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
async searchStories(opts: perigon.StoriesSearchOptions) {
|
async searchStories(opts: perigon.StoriesSearchOptions) {
|
||||||
return this.ky
|
const searchParams = sanitizeSearchParams({
|
||||||
.get('stories/all', {
|
sortBy: 'relevance',
|
||||||
searchParams: sanitizeSearchParams({
|
|
||||||
...opts,
|
...opts,
|
||||||
apiKey: this.apiKey,
|
apiKey: this.apiKey,
|
||||||
size: Math.max(
|
size: Math.max(
|
||||||
1,
|
1,
|
||||||
Math.min(
|
Math.min(perigon.MAX_PAGE_SIZE, opts.size || perigon.DEFAULT_PAGE_SIZE)
|
||||||
perigon.MAX_PAGE_SIZE,
|
|
||||||
opts.size || perigon.DEFAULT_PAGE_SIZE
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
console.log('perigon.searchStories', searchParams)
|
||||||
|
|
||||||
|
return this.ky
|
||||||
|
.get('stories/all', {
|
||||||
|
searchParams
|
||||||
})
|
})
|
||||||
.json<perigon.StoriesSearchResponse>()
|
.json<perigon.StoriesSearchResponse>()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import type { Simplify } from 'type-fest'
|
||||||
import defaultKy, { type KyInstance } from 'ky'
|
import defaultKy, { type KyInstance } from 'ky'
|
||||||
import pThrottle from 'p-throttle'
|
import pThrottle from 'p-throttle'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
@ -52,8 +53,13 @@ export namespace proxycurl {
|
||||||
typeof CompanyProfileEndpointParamsQueryClassSchema
|
typeof CompanyProfileEndpointParamsQueryClassSchema
|
||||||
>
|
>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requires one of:
|
||||||
|
* - `facebook_profile_url`
|
||||||
|
* - `linkedin_profile_url`
|
||||||
|
* - `twitter_profile_url`
|
||||||
|
*/
|
||||||
export const PersonProfileEndpointParamsQueryClassSchema = z.object({
|
export const PersonProfileEndpointParamsQueryClassSchema = z.object({
|
||||||
// requires one of `facebook_profile_url`, `linkedin_profile_url`, or `twitter_profile_url`
|
|
||||||
facebook_profile_url: z.string().optional(),
|
facebook_profile_url: z.string().optional(),
|
||||||
linkedin_profile_url: z.string().optional(),
|
linkedin_profile_url: z.string().optional(),
|
||||||
twitter_profile_url: z.string().optional(),
|
twitter_profile_url: z.string().optional(),
|
||||||
|
@ -68,8 +74,8 @@ export namespace proxycurl {
|
||||||
fallback_to_cache: FallbackToCacheSchema,
|
fallback_to_cache: FallbackToCacheSchema,
|
||||||
use_cache: UseCacheSchema
|
use_cache: UseCacheSchema
|
||||||
})
|
})
|
||||||
export type PersonProfileEndpointParamsQueryClass = z.infer<
|
export type PersonProfileEndpointParamsQueryClass = Simplify<
|
||||||
typeof PersonProfileEndpointParamsQueryClassSchema
|
z.infer<typeof PersonProfileEndpointParamsQueryClassSchema>
|
||||||
>
|
>
|
||||||
|
|
||||||
export const PersonLookupEndpointParamsQueryClassSchema = z.object({
|
export const PersonLookupEndpointParamsQueryClassSchema = z.object({
|
||||||
|
|
Ładowanie…
Reference in New Issue