import {z} from 'zod' export type GetApiV1SchedulesScheduleAForm5Args = {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, contributor_name?: Array | undefined, contributor_city?: Array | undefined, contributor_state?: Array | undefined, contributor_zip?: Array | undefined, contributor_employer?: Array | undefined, contributor_occupation?: Array | undefined, last_contribution_receipt_date?: string | undefined, last_contribution_amount?: number | undefined, report_year?: Array | undefined, report_type?: Array | undefined, contributor_type?: (Array<'individual' | 'committee'>) | undefined, two_year_transaction_period?: Array | undefined, per_page?: number | undefined, last_index?: number | undefined, sort?: string | undefined, sort_hide_null?: boolean | undefined, sort_null_only?: boolean | undefined, api_key?: string | undefined}; export type GetApiV1SchedulesScheduleAForm5Options = {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 form56 = z.object({amendment_indicator: z.string().nullable().optional(), contribution_amount: z.number().optional(), contribution_receipt_date: z.string().nullable().optional(), contributor_city: z.string().nullable().optional(), contributor_employer: z.string().nullable().optional(), contributor_name: z.string().nullable().optional(), contributor_occupation: z.string().nullable().optional(), contributor_state: z.string().nullable().optional(), contributor_street_1: z.string().nullable().optional(), contributor_street_2: z.string().nullable().optional(), contributor_type: z.string().nullable().optional(), contributor_type_full: z.string().nullable().optional(), contributor_zip: z.string().nullable().optional(), file_number: z.number().int().nullable().optional(), filer_name: z.string().nullable().optional(), filing_form: z.string().nullable().optional(), image_number: z.string().optional(), link_id: z.number().int().nullable().optional(), load_date: z.string().nullable().optional(), original_sub_id: z.string().optional(), report_type: z.string().nullable().optional(), report_year: z.number().int().optional(), schedule_type: z.string().nullable().optional(), schedule_type_full: z.string().nullable().optional(), sub_id: z.string().optional(), transaction_id: z.string().nullable().optional(), two_year_transaction_period: z.number().int().nullable().optional()}); export const form56Page = z.object({pagination: seekInfo.optional(), results: z.array(form56).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_a_form5/ */ export const getApiV1SchedulesScheduleAForm5 = async (args: GetApiV1SchedulesScheduleAForm5Args, options: GetApiV1SchedulesScheduleAForm5Options) => { 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.contributor_name ?? []) query.append("contributor_name", String(item)) for (const item of args.contributor_city ?? []) query.append("contributor_city", String(item)) for (const item of args.contributor_state ?? []) query.append("contributor_state", String(item)) for (const item of args.contributor_zip ?? []) query.append("contributor_zip", String(item)) for (const item of args.contributor_employer ?? []) query.append("contributor_employer", String(item)) for (const item of args.contributor_occupation ?? []) query.append("contributor_occupation", String(item)) if (args.last_contribution_receipt_date != null) query.append("last_contribution_receipt_date", String(args.last_contribution_receipt_date)) if (args.last_contribution_amount != null) query.append("last_contribution_amount", String(args.last_contribution_amount)) for (const item of args.report_year ?? []) query.append("report_year", String(item)) for (const item of args.report_type ?? []) query.append("report_type", String(item)) for (const item of args.contributor_type ?? []) query.append("contributor_type", String(item)) for (const item of args.two_year_transaction_period ?? []) query.append("two_year_transaction_period", 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.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_a_form5/${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(form56Page, await res.json()) };