import {z} from 'zod' export type GetApiApiV1ProjectsProjectIdAnnotationsArgs = {project_id: string, page_id?: (string | null) | undefined, kind?: (Array<'note' | 'text' | 'callout' | 'line' | 'polyline' | 'rect' | 'ellipse' | 'polygon' | 'ink' | 'highlight' | 'stamp'> | null) | undefined, display_kind?: (Array | null) | undefined, status?: (Array<'accepted' | 'rejected' | 'completed' | 'cancelled' | 'none'> | null) | undefined, author_id?: (string | null) | undefined, author_kind?: ('user' | 'agent' | 'imported' | null) | undefined, visibility?: ('private' | 'project' | null) | undefined, q?: (string | null) | undefined, linked_condition_id?: (string | null) | undefined, include_deleted?: boolean | undefined, sort?: ('created_at' | 'updated_at' | 'page' | 'status' | 'subject' | 'author' | 'display_kind' | 'comments' | 'color') | undefined, direction?: ('asc' | 'desc') | undefined, cursor?: (string | null) | undefined, limit?: number | undefined}; export type GetApiApiV1ProjectsProjectIdAnnotationsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const annotationPointGeometryOutput = z.object({type: z.literal("point"), x: z.string(), y: z.string()}); export const annotationRectGeometryOutput = z.object({x: z.string(), y: z.string(), w: z.string(), h: z.string(), type: z.literal("rect")}); export const rectShapeOutput = z.object({x: z.string(), y: z.string(), w: z.string(), h: z.string()}); export const annotationCalloutGeometryOutput = z.object({type: z.literal("callout"), rect: rectShapeOutput, leader: z.array(z.array(z.unknown()))}); export const annotationPolylineGeometryOutput = z.object({type: z.literal("polyline"), points: z.array(z.array(z.unknown()))}); export const annotationPolygonGeometryOutput = z.object({type: z.literal("polygon"), points: z.array(z.array(z.unknown()))}); export const annotationInkGeometryOutput = z.object({type: z.literal("ink"), strokes: z.array(z.array(z.array(z.unknown())))}); export const annotationQuadsGeometryOutput = z.object({type: z.literal("quads"), quads: z.array(z.array(z.string()))}); export const borderEffect = z.object({cloudy: z.union([z.literal(1), z.literal(2)])}); export const annotationFontOutput = z.object({family: z.string().optional(), size_pts: z.string().optional(), color: z.string().nullable().optional(), align: z.enum(["left", "center", "right"]).optional()}); export const annotationStyleOutput = z.object({stroke_color: z.string().optional(), stroke_opacity: z.string().optional(), fill_color: z.string().nullable().optional(), fill_opacity: z.string().optional(), stroke_width: z.string().optional(), dash: z.array(z.string()).nullable().optional(), border_effect: borderEffect.nullable().optional(), line_endings: z.array(z.unknown()).nullable().optional(), font: annotationFontOutput.nullable().optional(), blend: z.enum(["normal", "multiply"]).optional(), rotation: z.string().optional(), stamp_attachment_id: z.string().nullable().optional()}); export const sourceSummary = z.object({origin: z.string().nullable().optional(), nm: z.string().nullable().optional(), import_id: z.string().nullable().optional()}); export const annotation = z.object({id: z.string(), project_id: z.string(), page_id: z.string(), kind: z.enum(["note", "text", "callout", "line", "polyline", "rect", "ellipse", "polygon", "ink", "highlight", "stamp"]), geometry: z.discriminatedUnion("type", [annotationPointGeometryOutput, annotationRectGeometryOutput, annotationCalloutGeometryOutput, annotationPolylineGeometryOutput, annotationPolygonGeometryOutput, annotationInkGeometryOutput, annotationQuadsGeometryOutput]), style: annotationStyleOutput, subject: z.string().nullable(), contents: z.string().nullable(), status: z.enum(["accepted", "rejected", "completed", "cancelled"]).nullable(), author_id: z.string().nullable(), author_name: z.string(), author_kind: z.enum(["user", "agent", "imported"]), visibility: z.enum(["private", "project"]), locked: z.boolean(), bbox_x: z.string(), bbox_y: z.string(), bbox_w: z.string(), bbox_h: z.string(), display_kind: z.string(), row_version: z.number().int(), created_at: z.string(), updated_at: z.string(), deleted_at: z.string().nullable(), source: sourceSummary.nullable().optional()}); export const annotationListRow = z.object({annotation: annotation, drawing_id: z.string(), drawing_name: z.string(), page_number: z.number().int(), sheet_number: z.string().nullable(), comment_count: z.number().int().gte(0).optional()}); export const annotationListResponse = z.object({items: z.array(annotationListRow).optional(), next_cursor: 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 }; /** * List Annotations * * GET /api/v1/projects/{project_id}/annotations */ export const getApiApiV1ProjectsProjectIdAnnotations = async (args: GetApiApiV1ProjectsProjectIdAnnotationsArgs, options: GetApiApiV1ProjectsProjectIdAnnotationsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page_id != null) query.append("page_id", String(args.page_id)) for (const item of args.kind ?? []) query.append("kind", String(item)) for (const item of args.display_kind ?? []) query.append("display_kind", String(item)) for (const item of args.status ?? []) query.append("status", String(item)) if (args.author_id != null) query.append("author_id", String(args.author_id)) if (args.author_kind != null) query.append("author_kind", String(args.author_kind)) if (args.visibility != null) query.append("visibility", String(args.visibility)) if (args.q != null) query.append("q", String(args.q)) if (args.linked_condition_id != null) query.append("linked_condition_id", String(args.linked_condition_id)) if (args.include_deleted != null) query.append("include_deleted", String(args.include_deleted)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.direction != null) query.append("direction", String(args.direction)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.project_id))}/annotations${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(annotationListResponse, await res.json()) };