import {z} from 'zod' export type GetApiV1SchedulesScheduleEArgs = {image_number?: Array | undefined, min_image_number?: string | undefined, max_image_number?: string | undefined, min_amount?: number | undefined, max_amount?: number | undefined, min_date?: string | undefined, max_date?: string | undefined, candidate_office?: (Array<'' | 'H' | 'S' | 'P'>) | undefined, candidate_party?: Array | undefined, candidate_office_state?: Array | undefined, candidate_office_district?: Array | undefined, cycle?: Array | undefined, committee_id?: Array | undefined, candidate_id?: Array | undefined, filing_form?: Array | undefined, last_expenditure_date?: string | undefined, last_expenditure_amount?: number | undefined, last_office_total_ytd?: number | undefined, payee_name?: Array | undefined, support_oppose_indicator?: (Array<'S' | 'O'>) | undefined, last_support_oppose_indicator?: string | undefined, is_notice?: Array | undefined, min_dissemination_date?: string | undefined, max_dissemination_date?: string | undefined, min_filing_date?: string | undefined, max_filing_date?: string | undefined, most_recent?: boolean | undefined, q_spender?: Array | undefined, form_line_number?: Array | undefined, per_page?: number | undefined, last_index?: number | undefined, sort?: string | undefined, sort_hide_null?: boolean | undefined, sort_null_only?: boolean | undefined, sort_nulls_last?: boolean | undefined, api_key?: string | undefined}; export type GetApiV1SchedulesScheduleEOptions = {baseUrl: string, ApiKeyHeaderAuth?: string | undefined, ApiKeyQueryAuth?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const seekInfo = z.object({count: z.number().int().optional(), is_count_exact: z.boolean().optional(), last_indexes: z.unknown(), 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 committeeHistory = 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(), cycle: z.number().int(), cycles: z.array(z.number().int()).nullable().optional(), cycles_has_activity: z.array(z.number().int()).nullable().optional(), cycles_has_financial: 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(), filing_frequency: z.string().max(1).nullable().optional(), first_f1_date: z.string().nullable().optional(), first_file_date: z.string().nullable().optional(), is_active: z.boolean().nullable().optional(), jfc_committee: z.array(jFCCommittee).optional(), last_cycle_has_activity: z.number().int().nullable().optional(), last_cycle_has_financial: z.number().int().nullable().optional(), last_f1_date: z.string().nullable().optional(), last_file_date: z.string().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(), 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_name: z.string().max(100).nullable().optional(), zip: z.string().max(9).nullable().optional()}); export const scheduleE = z.object({action_code: z.string().nullable().optional(), action_code_full: z.string().nullable().optional(), amendment_indicator: z.string().nullable().optional(), amendment_number: z.number().int().nullable().optional(), back_reference_schedule_name: z.string().nullable().optional(), back_reference_transaction_id: z.string().nullable().optional(), candidate: z.unknown(), candidate_first_name: z.string().nullable().optional(), candidate_id: z.string().nullable().optional(), candidate_last_name: z.string().nullable().optional(), candidate_middle_name: z.string().nullable().optional(), candidate_name: z.string().nullable().optional(), candidate_office: z.string().nullable().optional(), candidate_office_district: z.string().nullable().optional(), candidate_office_state: z.string().nullable().optional(), candidate_party: z.string().nullable().optional(), candidate_prefix: z.string().nullable().optional(), candidate_suffix: z.string().nullable().optional(), category_code: z.string().nullable().optional(), category_code_full: z.string().nullable().optional(), committee: committeeHistory.optional(), committee_id: z.string().nullable().optional(), conduit_committee_city: z.string().nullable().optional(), conduit_committee_id: z.string().nullable().optional(), conduit_committee_name: z.string().nullable().optional(), conduit_committee_state: z.string().nullable().optional(), conduit_committee_street1: z.string().nullable().optional(), conduit_committee_street2: z.string().nullable().optional(), conduit_committee_zip: z.string().nullable().optional(), disbursement_dt: z.string().nullable().optional(), dissemination_date: z.string().nullable().optional(), election_type: z.string().nullable().optional(), election_type_full: z.string().nullable().optional(), expenditure_amount: z.number().optional(), expenditure_date: z.string().nullable().optional(), expenditure_description: z.string().nullable().optional(), file_number: z.number().int().nullable().optional(), filer_first_name: z.string().nullable().optional(), filer_last_name: z.string().nullable().optional(), filer_middle_name: z.string().nullable().optional(), filer_prefix: z.string().nullable().optional(), filer_suffix: z.string().nullable().optional(), filing_date: z.string().nullable().optional(), filing_form: z.string().nullable().optional(), form_line_number: z.string().optional(), image_number: z.string().optional(), independent_sign_date: z.string().nullable().optional(), independent_sign_name: z.string().nullable().optional(), is_notice: z.boolean().nullable().optional(), line_number: z.string().nullable().optional(), link_id: z.number().int().nullable().optional(), memo_code: z.string().nullable().optional(), memo_code_full: z.string().nullable().optional(), memo_text: z.string().nullable().optional(), memoed_subtotal: z.boolean().optional(), most_recent: z.boolean().nullable().optional(), notary_commission_expiration_date: z.string().nullable().optional(), notary_sign_date: z.string().nullable().optional(), notary_sign_name: z.string().nullable().optional(), office_total_ytd: z.number().optional(), original_sub_id: z.string().optional(), payee_city: z.string().nullable().optional(), payee_first_name: z.string().nullable().optional(), payee_last_name: z.string().nullable().optional(), payee_middle_name: z.string().nullable().optional(), payee_name: z.string().nullable().optional(), payee_prefix: z.string().nullable().optional(), payee_state: z.string().nullable().optional(), payee_street_1: z.string().nullable().optional(), payee_street_2: z.string().nullable().optional(), payee_suffix: z.string().nullable().optional(), payee_zip: z.string().nullable().optional(), pdf_url: z.string().nullable().optional(), previous_file_number: z.number().int().nullable().optional(), report_type: z.string().nullable().optional(), report_year: z.number().nullable().optional(), schedule_type: z.string().nullable().optional(), schedule_type_full: z.string().nullable().optional(), sub_id: z.string().optional(), support_oppose_indicator: z.string().nullable().optional(), transaction_id: z.string().nullable().optional()}); export const scheduleEPage = z.object({pagination: seekInfo.optional(), results: z.array(scheduleE).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/schedules/schedule_e/ */ export const getApiV1SchedulesScheduleE = async (args: GetApiV1SchedulesScheduleEArgs, options: GetApiV1SchedulesScheduleEOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyHeaderAuth, ApiKeyQueryAuth, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.image_number ?? []) query.append("image_number", String(item)) if (args.min_image_number != null) query.append("min_image_number", String(args.min_image_number)) if (args.max_image_number != null) query.append("max_image_number", String(args.max_image_number)) if (args.min_amount != null) query.append("min_amount", String(args.min_amount)) if (args.max_amount != null) query.append("max_amount", String(args.max_amount)) if (args.min_date != null) query.append("min_date", String(args.min_date)) if (args.max_date != null) query.append("max_date", String(args.max_date)) for (const item of args.candidate_office ?? []) query.append("candidate_office", String(item)) for (const item of args.candidate_party ?? []) query.append("candidate_party", String(item)) for (const item of args.candidate_office_state ?? []) query.append("candidate_office_state", String(item)) for (const item of args.candidate_office_district ?? []) query.append("candidate_office_district", String(item)) for (const item of args.cycle ?? []) query.append("cycle", String(item)) for (const item of args.committee_id ?? []) query.append("committee_id", String(item)) for (const item of args.candidate_id ?? []) query.append("candidate_id", String(item)) for (const item of args.filing_form ?? []) query.append("filing_form", String(item)) if (args.last_expenditure_date != null) query.append("last_expenditure_date", String(args.last_expenditure_date)) if (args.last_expenditure_amount != null) query.append("last_expenditure_amount", String(args.last_expenditure_amount)) if (args.last_office_total_ytd != null) query.append("last_office_total_ytd", String(args.last_office_total_ytd)) for (const item of args.payee_name ?? []) query.append("payee_name", String(item)) for (const item of args.support_oppose_indicator ?? []) query.append("support_oppose_indicator", String(item)) if (args.last_support_oppose_indicator != null) query.append("last_support_oppose_indicator", String(args.last_support_oppose_indicator)) for (const item of args.is_notice ?? []) query.append("is_notice", String(item)) if (args.min_dissemination_date != null) query.append("min_dissemination_date", String(args.min_dissemination_date)) if (args.max_dissemination_date != null) query.append("max_dissemination_date", String(args.max_dissemination_date)) if (args.min_filing_date != null) query.append("min_filing_date", String(args.min_filing_date)) if (args.max_filing_date != null) query.append("max_filing_date", String(args.max_filing_date)) if (args.most_recent != null) query.append("most_recent", String(args.most_recent)) for (const item of args.q_spender ?? []) query.append("q_spender", String(item)) for (const item of args.form_line_number ?? []) query.append("form_line_number", String(item)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.last_index != null) query.append("last_index", String(args.last_index)) 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/schedules/schedule_e/${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(scheduleEPage, await res.json()) };