import {z} from 'zod' export type GetApiApiProjectsProjectIdDocumentsArgs = {parentId?: string | undefined, deleted?: ('true' | 'false' | 'True' | 'False' | 'TRUE' | 'FALSE' | boolean) | undefined, search?: string | undefined, key?: string | undefined, keys?: string | undefined, ancestors?: ('true' | 'false' | 'True' | 'False' | 'TRUE' | 'FALSE' | boolean) | undefined, contentType?: string | undefined, directoriesOnly?: ('true' | 'false' | 'True' | 'False' | 'TRUE' | 'FALSE' | boolean) | undefined, directChildren?: ('true' | 'false' | 'True' | 'False' | 'TRUE' | 'FALSE' | boolean) | undefined, page?: number | undefined, perPage?: number | undefined, projectId: string}; export type GetApiApiProjectsProjectIdDocumentsOptions = {baseUrl: string, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiProjectsProjectIdDocumentsResponse = z.object({results: z.array(z.object({id: z.string(), key: z.string(), path: z.string(), name: z.string(), type: z.enum(["f", "d", "e"]), meta: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(), contentType: z.string().optional(), size: z.number().optional(), parentId: z.string().nullable().optional(), projectId: z.string(), publishedId: z.string().nullable().optional(), publishedAt: z.string().nullable().optional(), publishedBy: z.object({id: z.string(), email: z.string().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional()}).optional(), published: z.object({id: z.string(), name: z.string().nullable().optional(), parentId: z.string().nullable().optional(), status: z.string().optional(), content: z.unknown(), documentId: z.string().optional(), createdBy: z.object({id: z.string(), email: z.string().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional()}).optional(), createdAt: z.string().optional(), versions: z.array(z.unknown()).optional(), releases: z.array(z.object({id: z.string(), version: z.string().optional()})).optional()}).optional(), versions: z.array(z.object({id: z.string(), name: z.string().nullable().optional(), parentId: z.string().nullable().optional(), status: z.string().optional(), content: z.unknown(), documentId: z.string().optional(), createdBy: z.object({id: z.string(), email: z.string().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional()}).optional(), createdAt: z.string().optional(), versions: z.array(z.unknown()).optional(), releases: z.array(z.object({id: z.string(), version: z.string().optional()})).optional()})).optional(), changeRequests: z.array(z.object({id: z.string(), type: z.string(), status: z.string(), createdAt: z.string().optional()})).optional(), view: z.object({description: z.string().nullable().optional(), permissions: z.record(z.string(), z.enum(["edit:full", "edit:rules", "edit:values"])).nullable().optional()}).nullable().optional(), updatedAt: z.string().optional(), deletedAt: z.string().nullable().optional()})), paginate: z.object({current: z.number(), from: z.number(), to: z.number(), total: z.number(), pageSize: z.number()})}); 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 }; /** * List documents * * GET /api/projects/{projectId}/documents * * Also accepts auth: internalAuth */ export const getApiApiProjectsProjectIdDocuments = async (args: GetApiApiProjectsProjectIdDocumentsArgs, options: GetApiApiProjectsProjectIdDocumentsOptions) => { const {baseUrl, fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.parentId != null) query.append("parentId", String(args.parentId)) if (args.deleted != null) query.append("deleted", String(args.deleted)) if (args.search != null) query.append("search", String(args.search)) if (args.key != null) query.append("key", String(args.key)) if (args.keys != null) query.append("keys", String(args.keys)) if (args.ancestors != null) query.append("ancestors", String(args.ancestors)) if (args.contentType != null) query.append("contentType", String(args.contentType)) if (args.directoriesOnly != null) query.append("directoriesOnly", String(args.directoriesOnly)) if (args.directChildren != null) query.append("directChildren", String(args.directChildren)) if (args.page != null) query.append("page", String(args.page)) if (args.perPage != null) query.append("perPage", String(args.perPage)) if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/projects/${encodeURIComponent(String(args.projectId))}/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(getApiApiProjectsProjectIdDocumentsResponse, await res.json()) };