import {z} from 'zod' export type GetApiV1CanvasesCanvasKeyObjectsArgs = {canvas_key: string, type?: ('cell' | 'component' | 'connector' | 'ellipse' | 'embed' | 'frame' | 'group' | 'image' | 'file' | 'line' | 'pencil' | 'polygon' | 'rectangle' | 'stamp' | 'thread' | 'text' | 'sticky_note') | undefined, connection_key?: string | undefined}; export type GetApiV1CanvasesCanvasKeyObjectsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const dateTime = z.string(); export const canvasObject = z.object({key: z.string(), type: z.union([z.literal("cell"), z.literal("component"), z.literal("connector"), z.literal("ellipse"), z.literal("embed"), z.literal("frame"), z.literal("group"), z.literal("image"), z.literal("file"), z.literal("line"), z.literal("pencil"), z.literal("polygon"), z.literal("rectangle"), z.literal("stamp"), z.literal("thread"), z.literal("text"), z.literal("sticky_note")]), cell_name: z.string().optional(), cell_type: z.union([z.literal("code"), z.literal("python"), z.literal("csv"), z.literal("api"), z.literal("string"), z.literal("number"), z.literal("date"), z.literal("single_select"), z.literal("mcp"), z.literal("multiple_select"), z.literal("slider"), z.literal("toggle"), z.literal("table"), z.literal("table_filter"), z.literal("visual")]).optional(), catalog_key: z.string().optional(), content: z.string().optional(), frame_key: z.string().optional(), group_key: z.string().optional(), connection_key: z.string().optional(), file_mime_type: z.string().optional(), file_name: z.string().optional(), file_reference: z.string().optional(), file_size: z.number().optional(), file_url: z.string().optional(), image_url: z.string().optional(), modified_at: dateTime.optional(), modified_by: z.string().optional(), title: z.string().optional()}); export const getApiV1CanvasesCanvasKeyObjectsResponse = z.object({success: z.literal(true), request_id: z.string(), result: z.object({objects: z.array(canvasObject)})}); 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 canvas objects * * GET /v1/canvases/:canvas_key/objects */ export const getApiV1CanvasesCanvasKeyObjects = async (args: GetApiV1CanvasesCanvasKeyObjectsArgs, options?: GetApiV1CanvasesCanvasKeyObjectsOptions) => { const {baseUrl = "https://api.app.count.co/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (args.connection_key != null) query.append("connection_key", String(args.connection_key)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/canvases/:canvas_key/objects${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(getApiV1CanvasesCanvasKeyObjectsResponse, await res.json()) };