import {z} from 'zod' export type GetApiApiV1UsRulemakingDocketsDocketIdDocumentsArgs = {docket_id: string, documentType?: (string | null) | undefined, openForComment?: (boolean | null) | undefined, postedFrom?: (string | null) | undefined, postedTo?: (string | null) | undefined, limit?: number | undefined, cursor?: (string | null) | undefined, 'Idempotency-Key'?: (string | null) | undefined}; export type GetApiApiV1UsRulemakingDocketsDocketIdDocumentsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const rulemakingDocument = z.object({documentId: z.string(), docketId: z.string().nullable().optional(), agencyId: z.string().nullable().optional(), documentType: z.string().nullable().optional(), subtype: z.string().nullable().optional(), title: z.string().nullable().optional(), frDocNum: z.string().nullable().optional(), frDocNumNorm: z.string().nullable().optional(), postedAt: z.string().nullable().optional(), commentStartAt: z.string().nullable().optional(), commentEndAt: z.string().nullable().optional(), openForComment: z.boolean().nullable().optional(), withinCommentPeriod: z.boolean().nullable().optional(), allowLateComments: z.boolean().nullable().optional(), withdrawn: z.boolean().nullable().optional(), lastModifiedAt: z.string().nullable().optional(), cfrPart: z.string().nullable().optional(), frPages: z.string().nullable().optional(), commentCount: z.number().int().nullable().optional(), commentCountAsOf: z.string().nullable().optional(), sourceUrl: z.string(), asOf: z.string().nullable().optional()}); export const documentListResponse = z.object({processingTimeMs: z.number().optional(), creditsConsumed: z.number().int().optional(), docketId: z.string(), documents: z.array(rulemakingDocument), nextCursor: z.string().nullable().optional(), note: 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 }; /** * Documents of one docket, oldest first * * GET /api/v1/us/rulemaking/dockets/{docket_id}/documents * * Also accepts auth: ApiKeyHeader */ export const getApiApiV1UsRulemakingDocketsDocketIdDocuments = async (args: GetApiApiV1UsRulemakingDocketsDocketIdDocumentsArgs, options?: GetApiApiV1UsRulemakingDocketsDocketIdDocumentsOptions) => { 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.documentType != null) query.append("documentType", String(args.documentType)) if (args.openForComment != null) query.append("openForComment", String(args.openForComment)) if (args.postedFrom != null) query.append("postedFrom", String(args.postedFrom)) if (args.postedTo != null) query.append("postedTo", String(args.postedTo)) 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/dockets/${encodeURIComponent(String(args.docket_id))}/documents${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(documentListResponse, await res.json()) };