import {z} from 'zod' export type CompaniesAdvancedSearchFilterItem = {field: 'country_code', operator: 'in', type: 'filter', value: Array} | {field: 'region_code', operator: 'in', type: 'filter', value: Array} | {field: 'city', operator: 'in' | 'begins_with', type: 'filter', value: Array | string} | {field: 'postal_code', operator: 'in' | 'begins_with' | 'in_range', type: 'filter', value: Array | string | {gte?: string | undefined, lte?: string | undefined}} | {field: 'geo', label?: string | undefined, operator: 'within', type: 'filter', value: {distance: number, latitude: number, longitude: number}} | {field: 'employee_count', operator: 'in_range', type: 'filter', value: {gte?: number | undefined, lte?: number | undefined}} | {field: 'employee_range', operator: 'in', type: 'filter', value: Array<'1-10' | '11-100' | '101-500' | '501-1.000' | '1.001-5.000' | '5.001-10.000' | '10.000+' | 'null' | null>} | {field: 'founded_year', operator: 'in_range', type: 'filter', value: {gte?: number | undefined, lte?: number | undefined}} | {field: 'revenue', operator: 'in_range', type: 'filter', value: {gte?: number | undefined, lte?: number | undefined}} | {field: 'role', operator: 'in', type: 'filter', value: Array<'standalone' | 'group' | 'subsidiary'>} | {field: 'name', operator: 'contains' | 'exactly_matches' | 'begins_with' | 'ends_with', type: 'filter', value: string} | {field: 'urls', operator: 'in', type: 'filter', value: Array} | {field: 'keywords', operator: 'in' | 'begins_with' | 'contains', type: 'filter', value: Array | string} | {field: 'industries', operator: 'in', type: 'filter', value: {classification: 'wz' | 'nace' | 'internal', codes: Array}} | {field: 'icp_ids', operator: 'in', type: 'filter', value: Array} | {field: 'lookalikes', operator: 'in', type: 'filter', value: {field: 'urls' | 'lists' | 'crm_opportunity_status', mode?: ('precise' | 'balanced' | 'broad') | undefined, values: Array}} | {field: 'has_ip_addresses', operator: 'is', type: 'filter', value: boolean} | {field: 'has_email', operator: 'is', type: 'filter', value: boolean} | {field: 'has_phone', operator: 'is', type: 'filter', value: boolean} | {field: 'has_url', operator: 'is', type: 'filter', value: boolean} | {field: 'has_facebook', operator: 'is', type: 'filter', value: boolean} | {field: 'has_instagram', operator: 'is', type: 'filter', value: boolean} | {field: 'has_linkedin', operator: 'is', type: 'filter', value: boolean} | {field: 'has_pinterest', operator: 'is', type: 'filter', value: boolean} | {field: 'has_twitter', operator: 'is', type: 'filter', value: boolean} | {field: 'has_xing', operator: 'is', type: 'filter', value: boolean} | {field: 'has_youtube', operator: 'is', type: 'filter', value: boolean} | {field: 'crm_connection_status', include_corporate_group?: boolean | undefined, operator: 'in', type: 'filter', value: Array<'has_connections' | 'has_primary_connection' | 'has_suggestions' | 'empty'>} | {field: 'crm_opportunity_status', include_corporate_group?: boolean | undefined, operator: 'in', type: 'filter', value: Array<'won' | 'open' | 'lost'>} | {field: 'tags', include_corporate_group?: boolean | undefined, operator: 'in', type: 'filter', value: Array} | {field: 'lists', include_corporate_group?: boolean | undefined, operator: 'in', type: 'filter', value: {include_corporate_group?: boolean | undefined, list_ids: Array}} | {field: 'contact_departments', operator: 'in', type: 'filter', value: Array<'management_department' | 'sales_department' | 'it_department' | 'business_project_management_department' | 'finance_controlling_department' | 'engineering_department' | 'hr_department' | 'marketing_department' | 'consulting_department' | 'media_communications_department' | 'support_department' | 'rd_department' | 'students_apprentices' | 'production_department' | 'logistics_department' | 'legal_compliance_department' | 'qm_department' | 'product_department' | 'purchasing_department'>} | {field: 'contact_hierarchy_level', operator: 'in', type: 'filter', value: Array<'employees' | 'middle_management' | 'top_management'>} | {field: 'contact_position', operator: 'in' | 'begins_with' | 'contains', type: 'filter', value: Array | string} | {field: 'contact_country_code', operator: 'in', type: 'filter', value: Array} | {field: 'contact_buyer_persona_ids', operator: 'in', type: 'filter', value: Array} | {items: Array, negated?: boolean | undefined, operator: 'and' | 'or', type: 'group'}; export type CreateApiV1ListsBatchAddToListJobsArgs = {account_id: string, body: {data: {attributes: {advanced_search?: ({excluded_company_ids?: Array | undefined, filters: {items: Array, operator: 'and' | 'or', type: 'group'}, page?: ({size?: number | undefined}) | undefined, sort?: ({direction?: ('asc' | 'desc') | undefined, field?: string | undefined}) | undefined}) | undefined, items: Array<{id: string, type: 'company' | 'contact'}>, list_id: string} | {advanced_search: {excluded_company_ids?: Array | undefined, filters: {items: Array, operator: 'and' | 'or', type: 'group'}, page?: ({size?: number | undefined}) | undefined, sort?: ({direction?: ('asc' | 'desc') | undefined, field?: string | undefined}) | undefined}, items?: (Array<{id: string, type: 'company' | 'contact'}>) | undefined, list_id: string}, type?: string | undefined}}}; export type CreateApiV1ListsBatchAddToListJobsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const companiesAdvancedSearchFilterItem: z.ZodType = z.union([z.object({field: z.literal("country_code"), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.string())}), z.object({field: z.literal("region_code"), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.string())}), z.object({field: z.literal("city"), operator: z.enum(["in", "begins_with"]), type: z.literal("filter"), value: z.union([z.array(z.string()), z.string().min(1)])}), z.object({field: z.literal("postal_code"), operator: z.enum(["in", "begins_with", "in_range"]), type: z.literal("filter"), value: z.union([z.array(z.string()), z.string().min(1), z.object({gte: z.string().optional(), lte: z.string().optional()})])}), z.object({field: z.literal("geo"), label: z.string().optional(), operator: z.literal("within"), type: z.literal("filter"), value: z.object({distance: z.number().gte(0.01), latitude: z.number(), longitude: z.number()})}), z.object({field: z.literal("employee_count"), operator: z.literal("in_range"), type: z.literal("filter"), value: z.object({gte: z.number().int().gte(0).optional(), lte: z.number().int().gte(0).optional()})}), z.object({field: z.literal("employee_range"), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.enum(["1-10", "11-100", "101-500", "501-1.000", "1.001-5.000", "5.001-10.000", "10.000+", "null"]).nullable())}), z.object({field: z.literal("founded_year"), operator: z.literal("in_range"), type: z.literal("filter"), value: z.object({gte: z.number().int().optional(), lte: z.number().int().optional()})}), z.object({field: z.literal("revenue"), operator: z.literal("in_range"), type: z.literal("filter"), value: z.object({gte: z.number().int().gte(0).optional(), lte: z.number().int().gte(0).optional()})}), z.object({field: z.literal("role"), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.enum(["standalone", "group", "subsidiary"]))}), z.object({field: z.literal("name"), operator: z.enum(["contains", "exactly_matches", "begins_with", "ends_with"]), type: z.literal("filter"), value: z.string().min(1)}), z.object({field: z.literal("urls"), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.string())}), z.object({field: z.literal("keywords"), operator: z.enum(["in", "begins_with", "contains"]), type: z.literal("filter"), value: z.union([z.array(z.string()), z.string().min(1)])}), z.object({field: z.literal("industries"), operator: z.literal("in"), type: z.literal("filter"), value: z.object({classification: z.enum(["wz", "nace", "internal"]), codes: z.array(z.string())})}), z.object({field: z.literal("icp_ids"), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.string())}), z.object({field: z.literal("lookalikes"), operator: z.literal("in"), type: z.literal("filter"), value: z.object({field: z.enum(["urls", "lists", "crm_opportunity_status"]), mode: z.enum(["precise", "balanced", "broad"]).optional(), values: z.array(z.string())})}), z.object({field: z.literal("has_ip_addresses"), operator: z.literal("is"), type: z.literal("filter"), value: z.boolean()}), z.object({field: z.literal("has_email"), operator: z.literal("is"), type: z.literal("filter"), value: z.boolean()}), z.object({field: z.literal("has_phone"), operator: z.literal("is"), type: z.literal("filter"), value: z.boolean()}), z.object({field: z.literal("has_url"), operator: z.literal("is"), type: z.literal("filter"), value: z.boolean()}), z.object({field: z.literal("has_facebook"), operator: z.literal("is"), type: z.literal("filter"), value: z.boolean()}), z.object({field: z.literal("has_instagram"), operator: z.literal("is"), type: z.literal("filter"), value: z.boolean()}), z.object({field: z.literal("has_linkedin"), operator: z.literal("is"), type: z.literal("filter"), value: z.boolean()}), z.object({field: z.literal("has_pinterest"), operator: z.literal("is"), type: z.literal("filter"), value: z.boolean()}), z.object({field: z.literal("has_twitter"), operator: z.literal("is"), type: z.literal("filter"), value: z.boolean()}), z.object({field: z.literal("has_xing"), operator: z.literal("is"), type: z.literal("filter"), value: z.boolean()}), z.object({field: z.literal("has_youtube"), operator: z.literal("is"), type: z.literal("filter"), value: z.boolean()}), z.object({field: z.literal("crm_connection_status"), include_corporate_group: z.boolean().optional(), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.enum(["has_connections", "has_primary_connection", "has_suggestions", "empty"]))}), z.object({field: z.literal("crm_opportunity_status"), include_corporate_group: z.boolean().optional(), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.enum(["won", "open", "lost"]))}), z.object({field: z.literal("tags"), include_corporate_group: z.boolean().optional(), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.string())}), z.object({field: z.literal("lists"), include_corporate_group: z.boolean().optional(), operator: z.literal("in"), type: z.literal("filter"), value: z.object({include_corporate_group: z.boolean().optional(), list_ids: z.array(z.string())})}), z.object({field: z.literal("contact_departments"), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.enum(["management_department", "sales_department", "it_department", "business_project_management_department", "finance_controlling_department", "engineering_department", "hr_department", "marketing_department", "consulting_department", "media_communications_department", "support_department", "rd_department", "students_apprentices", "production_department", "logistics_department", "legal_compliance_department", "qm_department", "product_department", "purchasing_department"]))}), z.object({field: z.literal("contact_hierarchy_level"), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.enum(["employees", "middle_management", "top_management"]))}), z.object({field: z.literal("contact_position"), operator: z.enum(["in", "begins_with", "contains"]), type: z.literal("filter"), value: z.union([z.array(z.string()), z.string().min(1)])}), z.object({field: z.literal("contact_country_code"), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.string())}), z.object({field: z.literal("contact_buyer_persona_ids"), operator: z.literal("in"), type: z.literal("filter"), value: z.array(z.string())}), z.object({items: z.array(z.lazy(() => companiesAdvancedSearchFilterItem)), negated: z.boolean().optional(), operator: z.enum(["and", "or"]), type: z.literal("group")})]); export const batchAddToListJobV1 = z.object({attributes: z.object({completed_at: z.string().nullable(), configuration: z.union([z.object({advanced_search: z.object({excluded_company_ids: z.array(z.string()).optional(), filters: z.object({items: z.array(companiesAdvancedSearchFilterItem), operator: z.enum(["and", "or"]), type: z.literal("group")}), page: z.object({size: z.number().int().gte(1).optional()}).optional(), sort: z.object({direction: z.enum(["asc", "desc"]).optional(), field: z.string().optional()}).optional()}).optional(), items: z.array(z.object({id: z.string(), type: z.enum(["company", "contact"])})), list_id: z.string()}), z.object({advanced_search: z.object({excluded_company_ids: z.array(z.string()).optional(), filters: z.object({items: z.array(companiesAdvancedSearchFilterItem), operator: z.enum(["and", "or"]), type: z.literal("group")}), page: z.object({size: z.number().int().gte(1).optional()}).optional(), sort: z.object({direction: z.enum(["asc", "desc"]).optional(), field: z.string().optional()}).optional()}), items: z.array(z.object({id: z.string(), type: z.enum(["company", "contact"])})).optional(), list_id: z.string()})]), created_at: z.string(), errors: z.array(z.object({code: z.string(), title: z.string()})), results: z.array(z.object({id: z.string(), status: z.enum(["added", "already_present", "not_found"]), type: z.enum(["company", "contact"])})).optional(), status: z.enum(["running", "completed", "failed"]), summary: z.object({added: z.number().int().optional(), already_present: z.number().int().optional(), failed_count: z.number().int().optional(), list_size_after: z.number().int().optional(), list_size_before: z.number().int().optional(), not_found: z.number().int().optional(), scope_mismatch: z.number().int().optional()}).optional()}), id: z.string(), type: z.string()}); export const createApiV1ListsBatchAddToListJobsResponse = z.object({data: batchAddToListJobV1, meta: z.object({request_id: z.string()})}); 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 }; /** * Create Batch Add to List Job * * POST /v1/lists/batch-add-to-list-jobs * * Also accepts auth: OAuth2 */ export const createApiV1ListsBatchAddToListJobs = async (args: CreateApiV1ListsBatchAddToListJobsArgs, options?: CreateApiV1ListsBatchAddToListJobsOptions) => { const {baseUrl = "https://api.leadfeeder.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.account_id != null) query.append("account_id", String(args.account_id)) if (ApiKeyAuth !== undefined) headers.set("X-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/lists/batch-add-to-list-jobs${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(createApiV1ListsBatchAddToListJobsResponse, await res.json()) };