import {z} from 'zod' export type GetApiV3LiveDataSearchesIdArgs = {id: number}; export type GetApiV3LiveDataSearchesIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV3LiveDataSearchesIdResponse = z.object({id: z.number().int(), status: z.enum(["inProgress", "finished", "noMoreContacts", "manuallyPaused", "pausedDueToInsufficientCredits"]), startedAt: z.string(), contactsFound: z.number().int().optional(), usedCredits: z.number().int().optional(), userId: z.number().int().optional(), sequenceId: z.number().int().nullable().optional(), sequenceName: z.string().nullable().optional(), lists: z.array(z.object({id: z.number().int(), name: z.string()})).optional(), filters: z.object({accountListIds: z.array(z.object({value: z.number().int().gte(1), type: z.enum(["include", "exclude"]).optional()})).optional(), industries: z.array(z.object({value: z.string().max(200), type: z.enum(["include", "exclude"]).optional()})).optional(), companyLocations: z.array(z.object({value: z.string().max(200), type: z.enum(["include", "exclude"]).optional()})).optional(), companySizes: z.array(z.enum(["none", "selfEmployed", "ten", "fifty", "twoHundred", "fiveHundred", "oneThousand", "fiveThousand", "tenThousand", "overTenThousand"])).optional(), headcountGrowth: z.object({min: z.number().int().gte(0).nullable().optional(), max: z.number().int().gte(0).nullable().optional()}).nullable().optional(), departmentHeadcountGrowth: z.object({min: z.number().int().gte(0).nullable().optional(), max: z.number().int().gte(0).nullable().optional(), department: z.string().max(200)}).nullable().optional(), minRevenue: z.enum(["zeroMillion", "halfMillion", "oneMillion", "twoAndHalfMillion", "fiveMillion", "tenMillion", "twentyMillion", "fiftyMillion", "oneHundredMillion", "fiveHundredMillion", "oneThousandMillion", "overOneThousandMillion"]).nullable().optional(), maxRevenue: z.enum(["zeroMillion", "halfMillion", "oneMillion", "twoAndHalfMillion", "fiveMillion", "tenMillion", "twentyMillion", "fiftyMillion", "oneHundredMillion", "fiveHundredMillion", "oneThousandMillion", "overOneThousandMillion"]).nullable().optional(), accountKeywords: z.object({values: z.array(z.object({value: z.string().max(200), type: z.enum(["include", "exclude"]).optional()})).optional(), type: z.enum(["or", "and"]).optional()}).optional(), isHiringOnLinkedIn: z.boolean().optional(), contactLocations: z.array(z.object({value: z.string().max(200), type: z.enum(["include", "exclude"]).optional()})).optional(), jobTitles: z.array(z.object({value: z.string().max(200), type: z.enum(["include", "exclude"]).optional()})).optional(), departments: z.array(z.object({value: z.string().max(200), type: z.enum(["include", "exclude"]).optional()})).optional(), seniorities: z.array(z.string().min(1).max(200)).optional(), contactKeywords: z.object({values: z.array(z.object({value: z.string().max(200), type: z.enum(["include", "exclude"]).optional()})).optional(), type: z.enum(["or", "and"]).optional()}).optional()}).optional()}); 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 }; /** * Get a Live Data search * * GET /v3/live-data/searches/{id} */ export const getApiV3LiveDataSearchesId = async (args: GetApiV3LiveDataSearchesIdArgs, options?: GetApiV3LiveDataSearchesIdOptions) => { const {baseUrl = "https://api.reply.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/live-data/searches/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV3LiveDataSearchesIdResponse, await res.json()) };