import {z} from 'zod' export type GetApiV1WorkspacesIdFilesFileIdArgs = {id: string, file_id: string}; export type GetApiV1WorkspacesIdFilesFileIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const workspaceFileDetail = z.object({file_id: z.string(), workspace_id: z.string(), path: z.string(), file_name: z.string().optional(), file_type: z.string().optional(), size_bytes: z.number().int().optional(), version: z.number().int().optional(), observed_hash: z.string().nullable().optional(), ingested_hash: z.string().nullable().optional(), ingestion_status: z.enum(["discovered", "queued", "ingesting", "ingested", "stale", "expired", "failed", "not_required"]).optional(), ingested_at: z.string().nullable().optional(), category: z.string().nullable().optional(), access_label: z.string().nullable().optional(), access_label_source: z.string().nullable().optional(), graph_inclusion: z.enum(["auto", "include", "exclude"]).optional(), expires_at: z.string().nullable().optional(), labels: z.record(z.string(), z.string()).optional(), created_at: z.string().optional(), updated_at: z.string().optional(), download_url: z.string().nullable().optional(), preview_url: z.string().nullable().optional(), download_url_expires_at: z.string().nullable().optional()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Get a workspace file * * GET /v1/workspaces/{id}/files/{file_id} */ export const getApiV1WorkspacesIdFilesFileId = async (args: GetApiV1WorkspacesIdFilesFileIdArgs, options?: GetApiV1WorkspacesIdFilesFileIdOptions) => { const {baseUrl = "https://console.nace.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.id))}/files/${encodeURIComponent(String(args.file_id))}${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(workspaceFileDetail, await res.json()) };