import {z} from 'zod' export type ExistsFilter = {negate?: boolean | undefined, value: boolean}; export type JobSeniorityLevel = 'owner' | 'c-suite' | 'vice president' | 'director' | 'senior non-managerial' | 'manager' | 'partner' | 'non-managerial' | 'junior' | 'president' | 'senior manager' | 'advisor' | 'freelancer' | 'board member' | 'founder'; export type IncludesFilterJobSeniorityLevel = {negate?: boolean | undefined, values: Array}; export type JobDepartment = 'administration' | 'real estate' | 'healthcare' | 'partnerships' | 'c-suite' | 'design' | 'human resources' | 'engineering' | 'education' | 'strategy' | 'product' | 'sales' | 'r&d' | 'retail' | 'customer success' | 'security' | 'public service' | 'creative' | 'it' | 'support' | 'marketing' | 'trade' | 'legal' | 'operations' | 'procurement' | 'data' | 'manufacturing' | 'logistics' | 'finance'; export type IncludesFilterJobDepartment = {negate?: boolean | undefined, values: Array}; export type IncludesFilterBusinessId = {negate?: boolean | undefined, values: Array}; export type RangeFilterInt = {negate?: boolean | undefined, gte?: number | undefined, lte?: number | undefined}; export type IncludesFilterCountryCodeAlpha2 = {negate?: boolean | undefined, values: Array}; export type IncludesFilterRegionCode = {negate?: boolean | undefined, values: Array}; export type NumberOfEmployeesRange = '1-10' | '11-50' | '51-200' | '201-500' | '501-1000' | '1001-5000' | '5001-10000' | '10001+'; export type IncludesFilterNumberOfEmployeesRange = {negate?: boolean | undefined, values: Array}; export type RevenueRange = '0-500K' | '500K-1M' | '1M-5M' | '5M-10M' | '10M-25M' | '25M-75M' | '75M-200M' | '200M-500M' | '500M-1B' | '1B-10B' | '10B-100B' | '100B-1T' | '1T-10T' | '10T+'; export type IncludesFilterRevenueRange = {negate?: boolean | undefined, values: Array}; export type IncludesFilterStandardizedText = {negate?: boolean | undefined, values: Array}; export type IncludesFilterNAICS = {negate?: boolean | undefined, values: Array}; export type IncludesFilterText = {negate?: boolean | undefined, values: Array}; export type JobTitleFilter = {negate?: boolean | undefined, values: Array, include_related_job_titles?: (boolean | null) | undefined}; export type AnyMatchFilterOrganizationName = {negate?: boolean | undefined, values: Array}; export type ProspectsFetchFilters = {has_email?: ExistsFilter | undefined, has_phone_number?: ExistsFilter | undefined, job_level?: IncludesFilterJobSeniorityLevel | undefined, job_department?: IncludesFilterJobDepartment | undefined, business_id?: IncludesFilterBusinessId | undefined, total_experience_months?: RangeFilterInt | undefined, country_code?: IncludesFilterCountryCodeAlpha2 | undefined, region_country_code?: IncludesFilterRegionCode | undefined, current_role_months?: RangeFilterInt | undefined, company_size?: IncludesFilterNumberOfEmployeesRange | undefined, company_revenue?: IncludesFilterRevenueRange | undefined, google_category?: IncludesFilterStandardizedText | undefined, naics_category?: IncludesFilterNAICS | undefined, linkedin_category?: IncludesFilterText | undefined, job_title?: JobTitleFilter | undefined, company_country_code?: IncludesFilterCountryCodeAlpha2 | undefined, company_region_country_code?: IncludesFilterRegionCode | undefined, city_region_country?: IncludesFilterText | undefined, company_name?: AnyMatchFilterOrganizationName | undefined, has_website?: (ExistsFilter | null) | undefined}; export type ProspectsStatsRequest = {request_context?: (Record | null) | undefined, filters: ProspectsFetchFilters}; export type CreateApiV1ProspectsStatsArgs = {tenant?: string | undefined, body: ProspectsStatsRequest}; export type CreateApiV1ProspectsStatsOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const requestStatus = z.enum(["success", "miss", "failure"]); export const responseContext = z.object({correlation_id: z.string(), request_status: requestStatus, time_took_in_seconds: z.number()}); export const prospectsStats = z.object({job_departments_per_location: z.object({}).optional(), total_per_location: z.object({}).optional()}); export const prospectsStatsResponse = z.object({response_context: responseContext, total_results: z.number().int(), stats: prospectsStats}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Prospect Fetch Stats * * POST /v1/prospects/stats * * Also accepts auth: APIKeyHeader */ export const createApiV1ProspectsStats = async (args: CreateApiV1ProspectsStatsArgs, options?: CreateApiV1ProspectsStatsOptions) => { const {baseUrl = "https://api.explorium.ai", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.tenant != null) headers.set("tenant", String(args.tenant)) if (APIKeyHeader !== undefined) headers.set("api_key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/prospects/stats${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(prospectsStatsResponse, await res.json()) };