import {z} from 'zod' export type GetApiV0WorkflowsArgs = {project_id?: string | undefined, id?: string | undefined, name?: string | undefined, created_by?: string | undefined, created_on?: string | undefined, updated_at?: string | undefined, offset?: number | undefined, limit?: number | undefined}; export type GetApiV0WorkflowsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const dexterListWorkflowItem = z.object({id: z.string().optional(), project_id: z.string().optional(), legacy_project_id: z.string().optional(), name: z.string().optional(), created_by: z.string().optional(), description: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const commonPagination = z.object({limit: z.number().int().optional(), offset: z.number().int().optional(), total: z.number().int().optional()}); export const dexterListWorkflowsTransformerResponse = z.object({workflows: z.array(dexterListWorkflowItem).optional(), pagination: commonPagination.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 workflows * * GET /v0/workflows */ export const getApiV0Workflows = async (args: GetApiV0WorkflowsArgs, options?: GetApiV0WorkflowsOptions) => { const {baseUrl = "https://api.pixxel.space", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.project_id != null) query.append("project_id", String(args.project_id)) if (args.id != null) query.append("id", String(args.id)) if (args.name != null) query.append("name", String(args.name)) if (args.created_by != null) query.append("created_by", String(args.created_by)) if (args.created_on != null) query.append("created_on", String(args.created_on)) if (args.updated_at != null) query.append("updated_at", String(args.updated_at)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v0/workflows${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(dexterListWorkflowsTransformerResponse, await res.json()) };