import {z} from 'zod' export type GetApiApiV1DocumentDocumentNotesArgs = {jq_filters?: {[key: string]: string} | undefined, project_id?: string | undefined, document_id?: string | undefined, force?: boolean | undefined, export_to?: boolean | undefined}; export type GetApiApiV1DocumentDocumentNotesOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const documentNoteDetailUser = z.object({pk: z.number().int().optional(), first_name: z.string().max(30).optional(), last_name: z.string().max(150).optional(), username: z.string().max(150), photo: z.string().optional(), name: z.string().max(255).optional(), initials: z.string().max(2).optional()}); export const documentNoteDetail = z.object({pk: z.number().int().optional(), note: z.string(), timestamp: z.string().optional(), user: documentNoteDetailUser.optional(), location_start: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), location_end: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), document_id: z.number().int(), field_value_id: z.number().int().optional(), field_id: z.string().optional(), selections: z.array(z.object({})).optional()}); export const getApiApiV1DocumentDocumentNotesResponse = z.array(documentNoteDetail); 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 }; /** * Document Note List * * GET /api/v1/document/document-notes/ */ export const getApiApiV1DocumentDocumentNotes = async (args: GetApiApiV1DocumentDocumentNotesArgs, options: GetApiApiV1DocumentDocumentNotesOptions) => { const {baseUrl, fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.jq_filters != null) query.append("jq_filters", JSON.stringify(args.jq_filters)) if (args.project_id != null) query.append("project_id", String(args.project_id)) if (args.document_id != null) query.append("document_id", String(args.document_id)) if (args.force != null) query.append("force", String(args.force)) if (args.export_to != null) query.append("export_to", String(args.export_to)) if (AuthToken !== undefined) headers.set("Authorization", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/document/document-notes/${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(getApiApiV1DocumentDocumentNotesResponse, await res.json()) };