import {z} from 'zod' export type GetApiV1CandidateCandidateIdFilingsArgs = {page?: number | undefined, per_page?: number | undefined, committee_type?: string | undefined, cycle?: Array | undefined, is_amended?: boolean | undefined, most_recent?: boolean | undefined, report_type?: Array | undefined, request_type?: Array | undefined, document_type?: Array | undefined, beginning_image_number?: Array | undefined, report_year?: Array | undefined, min_receipt_date?: string | undefined, max_receipt_date?: string | undefined, form_type?: Array | undefined, state?: Array | undefined, district?: Array | undefined, office?: (Array<'' | 'H' | 'S' | 'P'>) | undefined, party?: Array | undefined, filer_type?: ('e-file' | 'paper') | undefined, file_number?: Array | undefined, primary_general_indicator?: Array | undefined, amendment_indicator?: (Array<'' | 'N' | 'A' | 'T' | 'C' | 'M' | 'S'>) | undefined, form_category?: Array | undefined, q_filer?: Array | undefined, sort?: Array | 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 GetApiV1CandidateCandidateIdFilingsOptions = {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 filings = z.object({additional_bank_names: z.array(z.string()).nullable().optional(), amendment_chain: z.array(z.number().int()).optional(), amendment_indicator: z.string().nullable().optional(), amendment_version: z.number().int().nullable().optional(), bank_depository_city: z.string().nullable().optional(), bank_depository_name: z.string().nullable().optional(), bank_depository_state: z.string().nullable().optional(), bank_depository_street_1: z.string().nullable().optional(), bank_depository_street_2: z.string().nullable().optional(), bank_depository_zip: z.string().nullable().optional(), beginning_image_number: z.string().optional(), candidate_id: z.string().nullable().optional(), candidate_name: z.string().nullable().optional(), cash_on_hand_beginning_period: z.number().optional(), cash_on_hand_end_period: z.number().optional(), committee_id: z.string().nullable().optional(), committee_name: z.string().nullable().optional(), committee_type: z.string().nullable().optional(), coverage_end_date: z.string().nullable().optional(), coverage_start_date: z.string().nullable().optional(), csv_url: z.string().optional(), cycle: z.number().int().nullable().optional(), debts_owed_by_committee: z.number().optional(), debts_owed_to_committee: z.number().optional(), document_description: z.string().optional(), document_type: z.string().nullable().optional(), document_type_full: z.string().nullable().optional(), election_year: z.number().int().nullable().optional(), ending_image_number: z.string().optional(), fec_file_id: z.string().optional(), fec_url: z.string().optional(), file_number: z.number().int().nullable().optional(), form_category: z.string().nullable().optional(), form_type: z.string().nullable().optional(), house_personal_funds: z.number().optional(), html_url: z.string().nullable().optional(), is_amended: z.boolean().nullable().optional(), means_filed: z.string().nullable().optional(), most_recent: z.boolean().nullable().optional(), most_recent_file_number: z.number().int().nullable().optional(), net_donations: z.number().optional(), office: z.string().nullable().optional(), opposition_personal_funds: z.number().optional(), pages: z.number().int().nullable().optional(), party: z.string().nullable().optional(), pdf_url: z.string().nullable().optional(), previous_file_number: z.number().int().nullable().optional(), primary_general_indicator: z.string().nullable().optional(), receipt_date: z.string().nullable().optional(), report_type: z.string().nullable().optional(), report_type_full: z.string().optional(), report_year: z.number().int().nullable().optional(), request_type: z.string().nullable().optional(), senate_personal_funds: z.number().optional(), state: z.string().nullable().optional(), sub_id: z.string().optional(), total_communication_cost: z.number().optional(), total_disbursements: z.number().optional(), total_independent_expenditures: z.number().optional(), total_individual_contributions: z.number().optional(), total_receipts: z.number().optional(), treasurer_name: z.string().nullable().optional(), update_date: z.string().nullable().optional()}); export const filingsPage = z.object({pagination: offsetInfo.optional(), results: z.array(filings).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}/filings/ */ export const getApiV1CandidateCandidateIdFilings = async (args: GetApiV1CandidateCandidateIdFilingsArgs, options: GetApiV1CandidateCandidateIdFilingsOptions) => { 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)) if (args.committee_type != null) query.append("committee_type", String(args.committee_type)) for (const item of args.cycle ?? []) query.append("cycle", String(item)) if (args.is_amended != null) query.append("is_amended", String(args.is_amended)) if (args.most_recent != null) query.append("most_recent", String(args.most_recent)) for (const item of args.report_type ?? []) query.append("report_type", String(item)) for (const item of args.request_type ?? []) query.append("request_type", String(item)) for (const item of args.document_type ?? []) query.append("document_type", String(item)) for (const item of args.beginning_image_number ?? []) query.append("beginning_image_number", String(item)) for (const item of args.report_year ?? []) query.append("report_year", String(item)) if (args.min_receipt_date != null) query.append("min_receipt_date", String(args.min_receipt_date)) if (args.max_receipt_date != null) query.append("max_receipt_date", String(args.max_receipt_date)) for (const item of args.form_type ?? []) query.append("form_type", String(item)) for (const item of args.state ?? []) query.append("state", String(item)) for (const item of args.district ?? []) query.append("district", String(item)) for (const item of args.office ?? []) query.append("office", String(item)) for (const item of args.party ?? []) query.append("party", String(item)) if (args.filer_type != null) query.append("filer_type", String(args.filer_type)) for (const item of args.file_number ?? []) query.append("file_number", String(item)) for (const item of args.primary_general_indicator ?? []) query.append("primary_general_indicator", String(item)) for (const item of args.amendment_indicator ?? []) query.append("amendment_indicator", String(item)) for (const item of args.form_category ?? []) query.append("form_category", String(item)) for (const item of args.q_filer ?? []) query.append("q_filer", String(item)) for (const item of args.sort ?? []) query.append("sort", String(item)) 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))}/filings/${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(filingsPage, await res.json()) };