import {z} from 'zod' export type PeopleWatchlistType = 'USER_MANAGED_WATCHLIST' | 'CUSTOMER_MANAGED_WATCHLIST' | 'USER_CONNECTIONS' | 'TEAM_CONNECTIONS' | 'GLOBAL_FIELD_LIST'; export type GetApiWatchlistsPeopleArgs = {person_urns?: Array | undefined, return_people_urns?: boolean | undefined, return_people_count?: boolean | undefined, watchlist_types?: Array | undefined}; export type GetApiWatchlistsPeopleOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const peopleWatchlistType = z.enum(["USER_MANAGED_WATCHLIST", "CUSTOMER_MANAGED_WATCHLIST", "USER_CONNECTIONS", "TEAM_CONNECTIONS", "GLOBAL_FIELD_LIST"]); export const listCustomFieldType = z.enum(["TEXT", "NUMBER", "DATE", "SINGLE_SELECT", "MULTI_SELECT", "PERSON", "WEBSITE", "CHECKBOX", "STATUS", "RECORD_REFERENCE"]); export const selectListCustomFieldValueOption = z.object({urn: z.string().optional(), name: z.string(), color: z.string()}); export const selectListCustomFieldMetadata = z.object({options: z.array(selectListCustomFieldValueOption).optional(), default: z.string().nullable().optional()}); export const numberListCustomFieldValueFormat = z.enum(["NUMBER", "PERCENT", "US_DOLLAR"]); export const numberListCustomFieldMetadata = z.object({format: numberListCustomFieldValueFormat.optional()}); export const dateListCustomFieldValueFormat = z.enum(["MM_DD_YYYY", "DD_MM_YYYY", "YYYY_MM_DD"]); export const dateListCustomFieldMetadata = z.object({format: dateListCustomFieldValueFormat.optional()}); export const personListCustomFieldValueMode = z.enum(["SINGLE", "MULTIPLE"]); export const personListCustomFieldMetadata = z.object({mode: personListCustomFieldValueMode}); export const recordReferenceListCustomFieldMetadata = z.object({record_type_urn: z.string(), allow_multiple: z.boolean(), mode: z.string().nullable().optional()}); export const checkboxListCustomFieldValue = z.object({value: z.boolean().nullable().optional()}); export const numberListCustomFieldValue = z.object({value: z.number().nullable().optional()}); export const singleListSelectCustomFieldValue = z.object({value: z.string().nullable().optional()}); export const textListCustomFieldValue = z.object({value: z.string().nullable().optional()}); export const multiSelectListCustomFieldValue = z.object({value: z.array(z.string()).optional()}); export const personListCustomFieldDefaultValueMode = z.enum(["FIXED_URN", "ADDED_BY_USER"]); export const personListCustomFieldDefaultValue = z.object({value: z.array(z.string()).optional(), mode: personListCustomFieldDefaultValueMode}); export const recordReferenceListCustomFieldValue = z.object({value: z.array(z.string()).optional()}); export const dateListCustomFieldDefaultValueMode = z.enum(["FIXED_DATE", "CREATED_AT"]); export const dateListCustomFieldDefaultValue = z.object({value: z.string().nullable().optional(), mode: dateListCustomFieldDefaultValueMode}); export const websiteListCustomFieldValue = z.object({value: z.string().nullable().optional()}); export const statusListCustomFieldValue = z.object({value: z.string().nullable().optional()}); export const personListCustomFieldOutput = z.object({created_at: z.string(), updated_at: z.string(), urn: z.union([z.string(), z.string(), z.string()]), list_urn: z.string(), name: z.string(), type: listCustomFieldType, metadata: z.union([selectListCustomFieldMetadata, numberListCustomFieldMetadata, dateListCustomFieldMetadata, personListCustomFieldMetadata, recordReferenceListCustomFieldMetadata]).nullable().optional(), default_value: z.union([checkboxListCustomFieldValue, numberListCustomFieldValue, singleListSelectCustomFieldValue, textListCustomFieldValue, multiSelectListCustomFieldValue, personListCustomFieldDefaultValue, recordReferenceListCustomFieldValue, dateListCustomFieldDefaultValue, websiteListCustomFieldValue, statusListCustomFieldValue]).nullable().optional()}); export const filter = z.object({field: z.string(), field_urn: z.string().nullable().optional(), comparator: z.string(), filter_value: z.unknown()}); export const filterGroupGeneratorId = z.enum(["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 const filterGroupGenerator = z.object({generator_id: filterGroupGeneratorId, arguments: z.object({})}); export const filterGroupOutput: z.ZodType = z.object({join_operator: z.enum(["and", "or"]), filters: z.array(filter).nullable().optional(), filter_groups: z.array(z.lazy(() => filterGroupOutput)).nullable().optional(), filter_group_generators: z.array(filterGroupGenerator).nullable().optional()}); export const pagination = z.object({start: z.number().int().nullable().optional(), page_size: z.number().int()}); export const sortContextArguments = z.object({saved_search_id: z.number().int().nullable().optional(), date_added_after: z.string().nullable().optional(), list_urn: z.union([z.string(), z.string()]).nullable().optional(), custom_field_urn: z.union([z.string(), z.string()]).nullable().optional(), company_id: z.number().int().nullable().optional()}); export const sortOutput = z.object({sort_field: z.string(), descending: z.boolean(), sort_context_values: sortContextArguments.nullable().optional()}); export const apiSearchQueryOutput = z.object({filter_group: filterGroupOutput, pagination: pagination, sort: z.array(sortOutput).optional(), controlled_filter_group: filterGroupOutput.nullable().optional(), merge_query_for_nested_fields: z.boolean().optional()}); export const listNamedViewDisplayType = z.enum(["GRID", "BOARD"]); export const personListNamedViewColumnViewSettings = z.object({entity_urn: z.union([z.string(), z.string(), z.string(), z.string()]), column_width: z.number().int().nullable().optional()}); export const personListNamedViewOutput = z.object({id: z.number().int().nullable(), entity_urn: z.string(), name: z.string(), list_urn: z.string(), visible_columns: z.array(z.union([z.string(), z.string(), z.string(), z.string()])), search_query: apiSearchQueryOutput.nullable().optional(), display_type: listNamedViewDisplayType, group_by_field: z.string().nullable().optional(), hide_empty_columns: z.boolean(), column_view_settings: z.array(personListNamedViewColumnViewSettings).nullable().optional()}); export const paginationMetadata = z.object({next: z.string().nullable().optional(), current: z.string().nullable().optional(), has_next: z.boolean()}); export const peopleWatchlistOutput = z.object({name: z.string(), shared_with_team: z.boolean(), entity_urn: z.string(), creator: z.string().nullable().optional(), owner: z.union([z.string(), z.string()]), people: z.array(z.string()).nullable().optional(), people_count: z.number().int().nullable().optional(), id: z.string(), user_watchlist_type: peopleWatchlistType, custom_fields: z.array(personListCustomFieldOutput).optional(), named_views: z.array(personListNamedViewOutput).optional(), named_views_order: z.array(z.string()).optional(), updated_at: z.string(), created_at: z.string(), page_info: paginationMetadata.nullable().optional()}); export const getApiWatchlistsPeopleResponse = z.array(peopleWatchlistOutput); 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 People Watchlists By Owner * * GET /watchlists/people */ export const getApiWatchlistsPeople = async (args: GetApiWatchlistsPeopleArgs, options: GetApiWatchlistsPeopleOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.person_urns ?? []) query.append("person_urns", String(item)) if (args.return_people_urns != null) query.append("return_people_urns", String(args.return_people_urns)) if (args.return_people_count != null) query.append("return_people_count", String(args.return_people_count)) for (const item of args.watchlist_types ?? []) query.append("watchlist_types", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/watchlists/people${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(getApiWatchlistsPeopleResponse, await res.json()) };