import {z} from 'zod' export type GetApiV1CandidateCandidateIdCommitteesArgs = {page?: number | undefined, per_page?: number | undefined, year?: Array | undefined, cycle?: Array | undefined, filing_frequency?: (Array<'' | 'A' | 'M' | 'N' | 'Q' | 'T' | 'W' | '-A' | '-T'>) | undefined, designation?: (Array<'' | 'A' | 'J' | 'P' | 'U' | 'B' | 'D'>) | undefined, organization_type?: (Array<'' | 'C' | 'L' | 'M' | 'T' | 'V' | 'W' | 'H' | 'I'>) | undefined, committee_type?: (Array<'' | 'C' | 'D' | 'E' | 'H' | 'I' | 'N' | 'O' | 'P' | 'Q' | 'S' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'>) | undefined, sort?: string | undefined, sort_hide_null?: boolean | undefined, sort_null_only?: boolean | undefined, sort_nulls_last?: boolean | undefined, api_key?: string | undefined, candidate_id: string}; export type GetApiV1CandidateCandidateIdCommitteesOptions = {baseUrl: string, ApiKeyHeaderAuth?: string | undefined, ApiKeyQueryAuth?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const offsetInfo = z.object({count: z.number().int().optional(), is_count_exact: z.boolean().optional(), page: z.number().int().optional(), pages: z.number().int().optional(), per_page: z.number().int().optional()}); export const jFCCommittee = z.object({joint_committee_id: z.string().nullable().optional(), joint_committee_name: z.string().max(100).nullable().optional()}); export const committeeDetail = z.object({affiliated_committee_name: z.string().max(100).nullable().optional(), candidate_ids: z.array(z.string()).nullable().optional(), city: z.string().max(50).nullable().optional(), committee_id: z.string(), committee_type: z.string().max(1).nullable().optional(), committee_type_full: z.string().max(50).nullable().optional(), custodian_city: z.string().max(50).nullable().optional(), custodian_name_1: z.string().max(50).nullable().optional(), custodian_name_2: z.string().max(50).nullable().optional(), custodian_name_full: z.string().max(100).nullable().optional(), custodian_name_middle: z.string().max(50).nullable().optional(), custodian_name_prefix: z.string().max(50).nullable().optional(), custodian_name_suffix: z.string().max(50).nullable().optional(), custodian_name_title: z.string().max(50).nullable().optional(), custodian_phone: z.string().max(15).nullable().optional(), custodian_state: z.string().max(2).nullable().optional(), custodian_street_1: z.string().max(50).nullable().optional(), custodian_street_2: z.string().max(50).nullable().optional(), custodian_zip: z.string().max(9).nullable().optional(), cycles: z.array(z.number().int()).nullable().optional(), designated_agent_city: z.string().max(50).nullable().optional(), designated_agent_first_name: z.string().max(50).nullable().optional(), designated_agent_last_name: z.string().max(50).nullable().optional(), designated_agent_middle_name: z.string().max(50).nullable().optional(), designated_agent_name: z.string().max(100).nullable().optional(), designated_agent_phone_number: z.string().max(50).nullable().optional(), designated_agent_prefix: z.string().max(50).nullable().optional(), designated_agent_state: z.string().max(50).nullable().optional(), designated_agent_street1: z.string().max(50).nullable().optional(), designated_agent_street2: z.string().max(50).nullable().optional(), designated_agent_suffix: z.string().max(50).nullable().optional(), designated_agent_title: z.string().max(50).nullable().optional(), designated_agent_zip: z.string().max(9).nullable().optional(), designation: z.string().max(1).nullable().optional(), designation_full: z.string().max(25).nullable().optional(), email: z.string().max(50).nullable().optional(), fax: z.string().max(10).nullable().optional(), filing_frequency: z.string().max(1).nullable().optional(), first_f1_date: z.string().nullable().optional(), first_file_date: z.string().nullable().optional(), form_type: z.string().max(3).nullable().optional(), jfc_committee: z.array(jFCCommittee).optional(), last_f1_date: z.string().nullable().optional(), last_file_date: z.string().nullable().optional(), leadership_pac: z.string().max(50).nullable().optional(), lobbyist_registrant_pac: z.string().max(1).nullable().optional(), name: z.string().max(100).nullable().optional(), organization_type: z.string().max(1).nullable().optional(), organization_type_full: z.string().max(100).nullable().optional(), party: z.string().max(3).nullable().optional(), party_full: z.string().max(50).nullable().optional(), party_type: z.string().max(3).nullable().optional(), party_type_full: z.string().max(15).nullable().optional(), sponsor_candidate_ids: z.array(z.string()).nullable().optional(), state: z.string().max(2).nullable().optional(), state_full: z.string().max(50).nullable().optional(), street_1: z.string().max(50).nullable().optional(), street_2: z.string().max(50).nullable().optional(), treasurer_city: z.string().max(50).nullable().optional(), treasurer_name: z.string().max(100).nullable().optional(), treasurer_name_1: z.string().max(50).nullable().optional(), treasurer_name_2: z.string().max(50).nullable().optional(), treasurer_name_middle: z.string().max(50).nullable().optional(), treasurer_name_prefix: z.string().max(50).nullable().optional(), treasurer_name_suffix: z.string().max(50).nullable().optional(), treasurer_name_title: z.string().max(50).nullable().optional(), treasurer_phone: z.string().max(15).nullable().optional(), treasurer_state: z.string().max(50).nullable().optional(), treasurer_street_1: z.string().max(50).nullable().optional(), treasurer_street_2: z.string().max(50).nullable().optional(), treasurer_zip: z.string().max(9).nullable().optional(), website: z.string().max(50).nullable().optional(), zip: z.string().max(9).nullable().optional()}); export const committeeDetailPage = z.object({pagination: offsetInfo.optional(), results: z.array(committeeDetail).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 /v1/candidate/{candidate_id}/committees/ */ export const getApiV1CandidateCandidateIdCommittees = async (args: GetApiV1CandidateCandidateIdCommitteesArgs, options: GetApiV1CandidateCandidateIdCommitteesOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyHeaderAuth, ApiKeyQueryAuth, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) for (const item of args.year ?? []) query.append("year", String(item)) for (const item of args.cycle ?? []) query.append("cycle", String(item)) for (const item of args.filing_frequency ?? []) query.append("filing_frequency", String(item)) for (const item of args.designation ?? []) query.append("designation", String(item)) for (const item of args.organization_type ?? []) query.append("organization_type", String(item)) for (const item of args.committee_type ?? []) query.append("committee_type", String(item)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.sort_hide_null != null) query.append("sort_hide_null", String(args.sort_hide_null)) if (args.sort_null_only != null) query.append("sort_null_only", String(args.sort_null_only)) if (args.sort_nulls_last != null) query.append("sort_nulls_last", String(args.sort_nulls_last)) if (args.api_key != null) query.append("api_key", String(args.api_key)) if (ApiKeyHeaderAuth !== undefined) headers.set("X-Api-Key", ApiKeyHeaderAuth) if (ApiKeyQueryAuth !== undefined) query.set("api_key", ApiKeyQueryAuth) if (apiKey !== undefined) query.set("api_key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/candidate/${encodeURIComponent(String(args.candidate_id))}/committees/${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(committeeDetailPage, await res.json()) };