import {z} from 'zod' export type SearchType = 'EVENT_FEED' | 'COMPANIES_LIST' | 'PERSONS' | 'TYPEAHEAD' | 'INVESTORS'; export type Filter = {field: string, field_urn?: (string | null) | undefined, comparator: string, filter_value: unknown}; export type FilterGroupGeneratorId = 'company_headcount' | 'search_v2_accelerator' | 'search_v2_company_funding_stage' | 'search_v2_company_funding_stage_simple' | 'search_v2_company_funding_total_range' | 'search_v2_company_funding_last_round_total_range' | 'search_v2_company_funding_undisclosed' | 'search_v2_company_currently_raising' | 'search_v2_company_funding_include_investors' | 'search_v2_company_funding_exclude_investors' | 'search_v2_company_funding_last_round_date' | 'search_v2_company_funding_foundation_date' | 'search_v2_company_funding_investors_deal_search' | 'search_v2_company_team_headcount_range' | 'search_v2_company_team_headcount_percent_growth_range' | 'search_v2_company_latest_web_traffic_range' | 'search_v2_company_web_traffic_percent_growth_range' | 'search_v2_company_headcount_department_percent_growth_range' | 'search_v2_company_socials_growth_range' | 'search_v2_company_team_highlights' | 'search_v2_company_sector_include_keywords' | 'search_v2_company_sector_exclude_keywords' | 'search_v2_company_sector_match_keywords' | 'search_v2_company_sector_include_industry_tags' | 'search_v2_company_sector_exclude_industry_tags' | 'search_v2_company_sector_include_business_tags' | 'search_v2_company_sector_exclude_business_tags' | 'search_v2_company_sector_include_technology_tags' | 'search_v2_company_sector_exclude_technology_tags' | 'search_v2_company_sector_preset' | 'search_v2_company_sector_include_tags' | 'search_v2_company_sector_exclude_tags' | 'search_v2_company_sector_product_categories' | 'search_v2_company_team_founding_experience' | 'search_v2_company_team_member_experience' | 'search_v2_company_team_notable_followers' | 'search_v2_company_team_notable_followers_count' | 'search_v2_company_list_and_more_initialized_date' | 'search_v2_company_list_and_more_updated_date' | 'search_v2_company_list_and_more_include_from_watchlist' | 'search_v2_company_list_and_more_exclude_from_watchlist' | 'search_v2_company_list_and_more_accelerators' | 'search_v2_company_list_and_more_location' | 'search_v2_company_list_and_more_continents' | 'search_v2_company_list_and_more_include_from_people_list' | 'search_v2_company_list_and_more_exclude_from_people_list' | 'search_v2_company_is_not_investor' | 'search_people_employees' | 'search_v2_people_education_experience' | 'search_v2_people_general_highlights' | 'search_v2_people_general_location' | 'search_v2_people_general_connections' | 'search_v2_person_network_membership' | 'search_v2_company_network_membership' | 'search_v2_investor_network_membership' | 'search_v2_people_general_linkedin_headlines' | 'search_v2_people_general_people_lists' | 'search_v2_people_current_experience' | 'search_v2_people_past_experience' | 'search_v2_people_general_correspondences' | 'search_v2_person_notable_followers' | 'search_v2_person_notable_followers_count' | 'search_v2_company_team_correspondences' | 'search_v2_semantic_search_filter' | 'search_v2_similar_company_search_filter' | 'search_v2_investor_aum_range' | 'search_v2_investor_check_size_range' | 'search_v2_investor_funded_company_location' | 'search_v2_investor_invested_stage' | 'search_v2_investor_latest_investment_date' | 'search_v2_investor_location' | 'search_v2_investor_num_deals_range' | 'search_v2_investor_team_size_range' | 'search_v2_investor_co_investors' | 'search_v2_investor_average_investment_size_range' | 'search_v2_investor_entry_stage_focus' | 'search_v2_investor_country_focus' | 'search_v2_investor_sector_focus' | 'search_v2_investor_funded_company' | 'search_v2_investor_website_keywords' | 'search_v2_investor_funded_company_sector_tags' | 'search_v2_investor_portfolio_details' | 'search_v2_investor_team_correspondences' | 'search_v2_investor_lists' | 'search_v2_investor_type' | 'search_v2_investor_primary_type' | 'search_v2_investor_secondary_types'; export type FilterGroupGenerator = {generator_id: FilterGroupGeneratorId, arguments: Record}; export type FilterGroupInput = {join_operator: 'and' | 'or', filters?: (Array | null) | undefined, filter_groups?: (Array | null) | undefined, merge_nested_fields?: boolean | undefined, filter_group_generators?: (Array | null) | undefined}; export type Pagination = {start?: (number | null) | undefined, page_size: number}; export type SortContextArguments = {saved_search_id?: (number | null) | undefined, date_added_after?: (string | null) | undefined, list_urn?: (string | string | null) | undefined, custom_field_urn?: (string | string | null) | undefined, company_id?: (number | null) | undefined}; export type ServicesMidtierSchemasSavedSearchSort = {sort_field: string, descending: boolean, sort_context_values?: (SortContextArguments | null) | undefined}; export type ApiSearchQueryInput = {filter_group: FilterGroupInput, pagination: Pagination, sort?: Array | undefined, controlled_filter_group?: (FilterGroupInput | null) | undefined, merge_query_for_nested_fields?: boolean | undefined}; export type SavedSearchColumnViewSettings = {entity_urn: string | string | string | string | string | string | string, column_width?: (number | null) | undefined}; export type SavedSearchInput = {name: string, is_private?: boolean | undefined, type?: SearchType | undefined, query: ApiSearchQueryInput, keywords: string, page?: (number | null) | undefined, page_size?: (number | null) | undefined, visible_columns?: (Array | null) | undefined, column_view_settings?: (Array | null) | undefined}; export type CreateApiSavedSearchesArgs = {body: SavedSearchInput}; export type CreateApiSavedSearchesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const dBOperationMetadata = z.object({count_total: z.number().int().nullable().optional(), count_changed: z.number().int().nullable().optional(), count_skipped: z.number().int().nullable().optional(), count_not_found: z.number().int().nullable().optional()}); export const resourceUrnResponseSavedSearchUrn = z.object({urn: z.string(), metadata: dBOperationMetadata.nullable().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 }; /** * Create Saved Search * * POST /saved_searches */ export const createApiSavedSearches = async (args: CreateApiSavedSearchesArgs, options: CreateApiSavedSearchesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/saved_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(resourceUrnResponseSavedSearchUrn, await res.json()) };