import {z} from 'zod' export type UpdateApiApiTasksTaskIdArgs = {taskId: string, body: {userId?: string | undefined, title?: string | undefined, description?: string | undefined, checked?: boolean | undefined, dueAt?: string | undefined, status?: string | undefined, priority?: string | undefined, assigneeId?: string | undefined, archived?: boolean | undefined, archivedAt?: string | undefined, startedAt?: string | undefined, checkedAt?: string | undefined, pinned?: boolean | undefined, rank?: number | undefined, attachmentIds?: Array | undefined, outcomeType?: string | undefined, aptletInstanceId?: string | undefined, fieldId?: string | undefined}}; export type UpdateApiApiTasksTaskIdOptions = {baseUrl?: string | undefined, ApiKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiApiTasksTaskIdResponse = z.object({ok: z.boolean().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 }; /** * Update a task * * PUT /api/tasks/{taskId} * * Also accepts auth: DelegateToken */ export const updateApiApiTasksTaskId = async (args: UpdateApiApiTasksTaskIdArgs, options?: UpdateApiApiTasksTaskIdOptions) => { const {baseUrl = "https://core-api.getaptly.com", fetch: fetchFn = fetch, ApiKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyHeader !== undefined) headers.set("x-token", ApiKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/api/tasks/${encodeURIComponent(String(args.taskId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiApiTasksTaskIdResponse, await res.json()) };