import {z} from 'zod' export type GetApiV1CongressMembersIdNetWorthArgs = {id: string, limit?: number | undefined}; export type GetApiV1CongressMembersIdNetWorthOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const listingNotice = z.object({status: z.string().nullable().optional(), ticker: z.string().nullable().optional(), delistedOn: z.string().nullable().optional(), successorTicker: z.string().nullable().optional()}); export const congressNetWorthDto = z.object({year: z.number().int().optional(), filedDate: z.string().optional(), netWorthMinimum: z.number().int().optional(), netWorthMaximum: z.number().int().optional(), assetCount: z.number().int().optional(), liabilityCount: z.number().int().optional()}); export const congressNetWorthDtoListResponse = z.object({listingNotice: listingNotice.optional(), data: z.array(congressNetWorthDto).nullable().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 }; /** * A congress member's net worth history from annual financial disclosures, newest first. Values are bands (minimum-maximum), read from electronically filed reports only — a missing year means no electronic filing, not zero net worth. * * GET /v1/congress/members/{id}/net-worth */ export const getApiV1CongressMembersIdNetWorth = async (args: GetApiV1CongressMembersIdNetWorthArgs, options?: GetApiV1CongressMembersIdNetWorthOptions) => { const {baseUrl = "https://api.equibles.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/congress/members/${encodeURIComponent(String(args.id))}/net-worth${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(congressNetWorthDtoListResponse, await res.json()) };