import {z} from 'zod' export type TaskQueueDocumentsDataInner = {pk?: number | undefined, name?: (string | null) | undefined, description?: (string | null) | undefined, document_type?: (string | null) | undefined}; export type TaskQueueReviewersDataInner = {pk?: number | undefined, username: string}; export type TaskQueue = {pk?: number | undefined, description?: (string | null) | undefined, documents?: Array | undefined, documents_data?: Array | undefined, completed_documents?: Array | undefined, completed_documents_data?: Array | undefined, reviewers?: Array | undefined, reviewers_data?: Array | undefined, progress?: string | undefined, data?: string | undefined}; export type CreateApiApiV1ProjectTaskQueuesArgs = {body: TaskQueue}; export type CreateApiApiV1ProjectTaskQueuesOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const taskQueueDocumentsDataInner = z.object({pk: z.number().int().optional(), name: z.string().max(1024).nullable().optional(), description: z.string().nullable().optional(), document_type: z.string().nullable().optional()}); export const taskQueueReviewersDataInner = z.object({pk: z.number().int().optional(), username: z.string().max(150)}); export const taskQueue = z.object({pk: z.number().int().optional(), description: z.string().nullable().optional(), documents: z.array(z.number().int()).optional(), documents_data: z.array(taskQueueDocumentsDataInner).optional(), completed_documents: z.array(z.number().int()).optional(), completed_documents_data: z.array(taskQueueDocumentsDataInner).optional(), reviewers: z.array(z.number().int()).optional(), reviewers_data: z.array(taskQueueReviewersDataInner).optional(), progress: z.string().optional(), data: z.string().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 }; /** * Create Task Queue * * POST /api/v1/project/task-queues/ */ export const createApiApiV1ProjectTaskQueues = async (args: CreateApiApiV1ProjectTaskQueuesArgs, options: CreateApiApiV1ProjectTaskQueuesOptions) => { const {baseUrl, fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AuthToken !== undefined) headers.set("Authorization", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/project/task-queues/${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(taskQueue, await res.json()) };