import {z} from 'zod' export type Tag = {key?: string | undefined, type?: string | undefined, value?: string | undefined}; export type HumanTaskTemplate = {createTime?: number | undefined, createdBy?: string | undefined, jsonSchema: {[key: string]: Record}, name: string, ownerApp?: string | undefined, tags?: Array | undefined, templateUI: {[key: string]: Record}, updateTime?: number | undefined, updatedBy?: string | undefined, version: number}; export type CreateApiApiHumanTemplateBulkArgs = {newVersion?: boolean | undefined, body: Array}; export type CreateApiApiHumanTemplateBulkOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const tag = z.object({key: z.string().optional(), type: z.string().optional(), value: z.string().optional()}); export const humanTaskTemplate = z.object({createTime: z.number().int().optional(), createdBy: z.string().optional(), jsonSchema: z.record(z.string(), z.object({})), name: z.string(), ownerApp: z.string().optional(), tags: z.array(tag).optional(), templateUI: z.record(z.string(), z.object({})), updateTime: z.number().int().optional(), updatedBy: z.string().optional(), version: z.number().int()}); export const createApiApiHumanTemplateBulkResponse = z.array(humanTaskTemplate); 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 }; /** * Save user form template * * POST /api/human/template/bulk */ export const createApiApiHumanTemplateBulk = async (args: CreateApiApiHumanTemplateBulkArgs, options?: CreateApiApiHumanTemplateBulkOptions) => { const {baseUrl = "https://developer.orkescloud.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.newVersion != null) query.append("newVersion", String(args.newVersion)) if (apiKey !== undefined) headers.set("X-Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/human/template/bulk${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(createApiApiHumanTemplateBulkResponse, await res.json()) };