import {z} from 'zod' export type GetApiApiV1UsRulemakingRinsRinAgendaArgs = {rin: string, from?: (string | null) | undefined, to?: (string | null) | undefined, limit?: number | undefined, cursor?: (string | null) | undefined, 'Idempotency-Key'?: (string | null) | undefined}; export type GetApiApiV1UsRulemakingRinsRinAgendaOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const timetableAction = z.object({action: z.string().nullable().optional(), dateRaw: z.string().nullable().optional(), dateValue: z.string().nullable().optional(), datePrecision: z.string().nullable().optional(), frCitation: z.string().nullable().optional(), frVolume: z.number().int().nullable().optional(), frPage: z.number().int().nullable().optional()}); export const agendaEdition = z.object({editionId: z.string(), season: z.string().nullable().optional(), year: z.number().int().nullable().optional(), runDate: z.string().nullable().optional(), title: z.string().nullable().optional(), abstract: z.string().nullable().optional(), stage: z.string().nullable().optional(), rinStatus: z.string().nullable().optional(), priority: z.string().nullable().optional(), major: z.string().nullable().optional(), agencyCode: z.string().nullable().optional(), agencyName: z.string().nullable().optional(), agencyAcronym: z.string().nullable().optional(), furtherInfoUrl: z.string().nullable().optional(), publicCommentUrl: z.string().nullable().optional(), sourceUrl: z.string().nullable().optional(), timetable: z.array(timetableAction).optional()}); export const agendaHistoryResponse = z.object({processingTimeMs: z.number().optional(), creditsConsumed: z.number().int().optional(), rin: z.string(), editions: z.array(agendaEdition), nextCursor: z.string().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 }; /** * Unified Agenda history of one RIN * * GET /api/v1/us/rulemaking/rins/{rin}/agenda * * Also accepts auth: ApiKeyHeader */ export const getApiApiV1UsRulemakingRinsRinAgenda = async (args: GetApiApiV1UsRulemakingRinsRinAgendaArgs, options?: GetApiApiV1UsRulemakingRinsRinAgendaOptions) => { const {baseUrl = "https://api.vaquill.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/us/rulemaking/rins/${encodeURIComponent(String(args.rin))}/agenda${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(agendaHistoryResponse, await res.json()) };