import {z} from 'zod' export type GetApiPublicV1ProspectListsArgs = {workspaceId?: string | undefined, ownerId?: string | undefined, type?: ('SALES_NAV' | 'CRUST' | 'WIZA_SEARCH' | 'CSV' | 'LINKEDIN_SEARCH' | 'SALES_NAV_SEARCH' | 'RECRUITER_SEARCH' | 'LINKEDIN_POST' | 'WARM_LIST' | 'CLAY' | 'DEEP_SEARCH' | 'PLAY') | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiPublicV1ProspectListsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPublicV1ProspectListsResponse = z.object({statusCode: z.number().optional(), status: z.boolean().optional(), message: z.string().optional(), data: z.object({lists: z.array(z.object({id: z.string().optional(), name: z.string().optional(), type: z.string().optional(), createdAt: z.string().optional(), people: z.number().optional(), owner: z.object({id: z.string().optional(), name: z.string().nullable().optional(), email: z.string().nullable().optional()}).optional(), play: z.object({playKey: z.string().nullable().optional(), campaignId: z.string().optional(), campaignName: z.string().nullable().optional(), campaignDeleted: z.boolean().optional()}).nullable().optional()})).optional(), pagination: z.object({limit: z.number().optional(), offset: z.number().optional(), total: z.number().optional(), hasMore: z.boolean().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 }; /** * List the saved lists in a workspace, newest first. Workspace owners, admins and managers see every seat's lists (filter one seat with ownerId); members see their own. type=PLAY returns the lists plays built, which stay after their campaign is deleted. * * GET /public/v1/prospect-lists */ export const getApiPublicV1ProspectLists = async (args: GetApiPublicV1ProspectListsArgs, options?: GetApiPublicV1ProspectListsOptions) => { const {baseUrl = "https://api.joinvalley.co", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.workspaceId != null) query.append("workspaceId", String(args.workspaceId)) if (args.ownerId != null) query.append("ownerId", String(args.ownerId)) if (args.type != null) query.append("type", String(args.type)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/public/v1/prospect-lists${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(getApiPublicV1ProspectListsResponse, await res.json()) };