import {z} from 'zod' export type GetApiPublishedDateIssuedStartDateDateIssuedEndDateArgs = {dateIssuedStartDate: string, dateIssuedEndDate: string, offsetMark?: string | undefined, offset?: number | undefined, pageSize: number, collection: string, congress?: string | 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, modifiedSince?: string | undefined, courtCode?: string | undefined, courtType?: string | undefined, state?: string | undefined, topic?: string | undefined, natureSuitCode?: string | undefined, natureSuit?: string | undefined, isGLP?: boolean | undefined}; export type GetApiPublishedDateIssuedStartDateDateIssuedEndDateOptions = {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 list of packages based on dateIssued value range * * GET /published/{dateIssuedStartDate}/{dateIssuedEndDate} */ export const getApiPublishedDateIssuedStartDateDateIssuedEndDate = async (args: GetApiPublishedDateIssuedStartDateDateIssuedEndDateArgs, options: GetApiPublishedDateIssuedStartDateDateIssuedEndDateOptions) => { 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.collection != null) query.append("collection", String(args.collection)) 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.modifiedSince != null) query.append("modifiedSince", String(args.modifiedSince)) 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.natureSuitCode != null) query.append("natureSuitCode", String(args.natureSuitCode)) if (args.natureSuit != null) query.append("natureSuit", String(args.natureSuit)) if (args.isGLP != null) query.append("isGLP", String(args.isGLP)) if (apiKeyScheme !== undefined) query.set("api_key", apiKeyScheme) const url = `${baseUrl.replace(/\/+$/, '')}/published/${encodeURIComponent(String(args.dateIssuedStartDate))}/${encodeURIComponent(String(args.dateIssuedEndDate))}${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()) };