import {z} from 'zod' export type GetApiCollectionsCollectionLastModifiedStartDateArgs = {collection: 'BILLS' | 'BILLSTATUS' | 'BUDGET' | 'CCAL' | 'CDIR' | 'CDOC' | 'CFR' | 'CHRG' | 'CMR' | 'COMPS' | 'CPD' | 'CPRT' | 'CREC' | 'CRECB' | 'CRI' | 'CRPT' | 'CZIC' | 'ECFR' | 'ECONI' | 'ERIC' | 'ERP' | 'FR' | 'GAOREPORTS' | 'GOVMAN' | 'GOVPUB' | 'GPO' | 'HJOURNAL' | 'HMAN' | 'HOB' | 'LSA' | 'PAI' | 'PLAW' | 'PPP' | 'SERIALSET' | 'SJOURNAL' | 'SMAN' | 'STATUTE' | 'USCODE' | 'USCOURTS' | 'USREPORTS', lastModifiedStartDate: string, offsetMark?: string | undefined, offset?: number | undefined, pageSize: number, congress?: number | undefined, docClass?: string | undefined, billVersion?: ('as' | 'ash' | 'ath' | 'ats' | 'cdh' | 'cds' | 'cph' | 'cps' | 'eah' | 'eas' | 'eh' | 'enr' | 'eph' | 'es' | 'fah' | 'fph' | 'fps' | 'hdh' | 'hds' | 'ih' | 'iph' | 'ips' | 'is' | 'lth' | 'lts' | 'nat' | 'oph' | 'ops' | 'pap' | 'pav' | 'pch' | 'pcs' | 'pp' | 'pwah' | 'rah' | 'ras' | 'rch' | 'rcs' | 'rdh' | 'rds' | 're' | 'reah' | 'renr' | 'res' | 'rfh' | 'rfs' | 'rft' | 'rh' | 'rhuc' | 'rih' | 'ris' | 'rs' | 'rth' | 'rts' | 's_p' | 'sas' | 'sc' | 'mostrecent') | undefined, courtCode?: string | undefined, courtType?: string | undefined, state?: string | undefined, topic?: string | undefined, isGLP?: boolean | undefined, natureSuitCode?: string | undefined, natureSuit?: string | undefined}; export type GetApiCollectionsCollectionLastModifiedStartDateOptions = {baseUrl: string, apiKeyScheme?: string | undefined, fetch?: typeof fetch | undefined}; export const packageInfo = z.object({packageId: z.string().optional(), lastModified: z.string().optional(), packageLink: z.string().optional(), docClass: z.string().optional(), title: z.string().optional(), congress: z.string().optional(), dateIssued: z.string().optional()}); export const collectionContainer = z.object({count: z.number().int().optional(), message: z.string().optional(), nextPage: z.string().optional(), previousPage: z.string().optional(), packages: z.array(packageInfo).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 }; /** * Retrieve new or updated packages for a collection given a start date and time * * GET /collections/{collection}/{lastModifiedStartDate} */ export const getApiCollectionsCollectionLastModifiedStartDate = async (args: GetApiCollectionsCollectionLastModifiedStartDateArgs, options: GetApiCollectionsCollectionLastModifiedStartDateOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKeyScheme} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offsetMark != null) query.append("offsetMark", String(args.offsetMark)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.congress != null) query.append("congress", String(args.congress)) if (args.docClass != null) query.append("docClass", String(args.docClass)) if (args.billVersion != null) query.append("billVersion", String(args.billVersion)) if (args.courtCode != null) query.append("courtCode", String(args.courtCode)) if (args.courtType != null) query.append("courtType", String(args.courtType)) if (args.state != null) query.append("state", String(args.state)) if (args.topic != null) query.append("topic", String(args.topic)) if (args.isGLP != null) query.append("isGLP", String(args.isGLP)) if (args.natureSuitCode != null) query.append("natureSuitCode", String(args.natureSuitCode)) if (args.natureSuit != null) query.append("natureSuit", String(args.natureSuit)) if (apiKeyScheme !== undefined) query.set("api_key", apiKeyScheme) const url = `${baseUrl.replace(/\/+$/, '')}/collections/${encodeURIComponent(String(args.collection))}/${encodeURIComponent(String(args.lastModifiedStartDate))}${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(collectionContainer, await res.json()) };