import {z} from 'zod' export type CreateApiV3LiveDataSearchesArgs = {body: {filters: {accountListIds?: (Array<{value: number, type?: ('include' | 'exclude') | undefined}>) | undefined, industries?: (Array<{value: string, type?: ('include' | 'exclude') | undefined}>) | undefined, companyLocations?: (Array<{value: string, type?: ('include' | 'exclude') | undefined}>) | undefined, companySizes?: (Array<'none' | 'selfEmployed' | 'ten' | 'fifty' | 'twoHundred' | 'fiveHundred' | 'oneThousand' | 'fiveThousand' | 'tenThousand' | 'overTenThousand'>) | undefined, headcountGrowth?: ({min?: (number | null) | undefined, max?: (number | null) | undefined} | null) | undefined, departmentHeadcountGrowth?: ({min?: (number | null) | undefined, max?: (number | null) | undefined, department: string} | null) | undefined, minRevenue?: ('zeroMillion' | 'halfMillion' | 'oneMillion' | 'twoAndHalfMillion' | 'fiveMillion' | 'tenMillion' | 'twentyMillion' | 'fiftyMillion' | 'oneHundredMillion' | 'fiveHundredMillion' | 'oneThousandMillion' | 'overOneThousandMillion' | null) | undefined, maxRevenue?: ('zeroMillion' | 'halfMillion' | 'oneMillion' | 'twoAndHalfMillion' | 'fiveMillion' | 'tenMillion' | 'twentyMillion' | 'fiftyMillion' | 'oneHundredMillion' | 'fiveHundredMillion' | 'oneThousandMillion' | 'overOneThousandMillion' | null) | undefined, accountKeywords?: ({values?: (Array<{value: string, type?: ('include' | 'exclude') | undefined}>) | undefined, type?: ('or' | 'and') | undefined}) | undefined, isHiringOnLinkedIn?: boolean | undefined, contactLocations?: (Array<{value: string, type?: ('include' | 'exclude') | undefined}>) | undefined, jobTitles?: (Array<{value: string, type?: ('include' | 'exclude') | undefined}>) | undefined, departments?: (Array<{value: string, type?: ('include' | 'exclude') | undefined}>) | undefined, seniorities?: Array | undefined, contactKeywords?: ({values?: (Array<{value: string, type?: ('include' | 'exclude') | undefined}>) | undefined, type?: ('or' | 'and') | undefined}) | undefined}, contactsCountToAdd: number, addContactsWithoutEmails?: boolean | undefined, maxPeoplePerCompany?: number | undefined, sequenceId?: (number | null) | undefined, listIds?: Array | undefined, referenceUrl?: (string | null) | undefined, searchContactPhones?: boolean | undefined}}; export type CreateApiV3LiveDataSearchesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV3LiveDataSearchesResponse = z.object({searchId: z.number().int()}); 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 }; /** * Start a Live Data search * * POST /v3/live-data/searches */ export const createApiV3LiveDataSearches = async (args: CreateApiV3LiveDataSearchesArgs, options?: CreateApiV3LiveDataSearchesOptions) => { const {baseUrl = "https://api.reply.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/live-data/searches${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(createApiV3LiveDataSearchesResponse, await res.json()) };