import {z} from 'zod' export type NodeVersionIdentifier = {node_id: string, version: string}; export type BulkNodeVersionsRequest = {node_versions: Array}; export type CreateApiBulkNodesVersionsArgs = {body: BulkNodeVersionsRequest}; export type CreateApiBulkNodesVersionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const nodeVersionIdentifier = z.object({node_id: z.string(), version: z.string()}); export const nodeVersionStatus = z.enum(["NodeVersionStatusActive", "NodeVersionStatusDeleted", "NodeVersionStatusBanned", "NodeVersionStatusPending", "NodeVersionStatusFlagged"]); export const nodeVersion = z.object({changelog: z.string().optional(), comfy_node_extract_status: z.string().optional(), createdAt: z.string().optional(), dependencies: z.array(z.string()).optional(), deprecated: z.boolean().optional(), downloadUrl: z.string().optional(), id: z.string().optional(), node_id: z.string().optional(), status: nodeVersionStatus.optional(), status_reason: z.string().optional(), supported_accelerators: z.array(z.string()).optional(), supported_comfyui_frontend_version: z.string().optional(), supported_comfyui_version: z.string().optional(), supported_os: z.array(z.string()).optional(), tags: z.array(z.string()).optional(), tags_admin: z.array(z.string()).optional(), version: z.string().optional()}); export const bulkNodeVersionResult = z.object({error_message: z.string().optional(), identifier: nodeVersionIdentifier, node_version: nodeVersion.optional(), status: z.enum(["success", "not_found", "error"])}); export const bulkNodeVersionsResponse = z.object({node_versions: z.array(bulkNodeVersionResult)}); 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 }; /** * Retrieve multiple node versions in a single request * * POST /bulk/nodes/versions */ export const createApiBulkNodesVersions = async (args: CreateApiBulkNodesVersionsArgs, options?: CreateApiBulkNodesVersionsOptions) => { const {baseUrl = "https://api.comfy.org", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/bulk/nodes/versions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(bulkNodeVersionsResponse, await res.json()) };