import {z} from 'zod' export type TaskAssignee = {id?: string | undefined, version?: string | undefined, createdDate?: number | undefined, lastModifiedDate?: number | undefined, plannedEffort?: number | undefined, userId?: string | undefined}; export type EntityReference = {entityId?: string | undefined, entityName?: string | undefined}; export type OnlyId = {id?: string | undefined}; export type CustomAttribute = {attributeDefinitionId?: string | undefined, booleanValue?: boolean | undefined, dateValue?: number | undefined, entityId?: string | undefined, entityReferences?: Array | undefined, numberValue?: unknown | undefined, selectedValueId?: string | undefined, selectedValues?: Array | undefined, stringValue?: string | undefined}; export type TaskMailAccount = {id?: string | undefined, version?: string | undefined, createdDate?: number | undefined, lastModifiedDate?: number | undefined, mailAccountId?: string | undefined, serverIdentifier?: string | undefined}; export type Task = {id?: string | undefined, version?: string | undefined, allowOverBooking?: boolean | undefined, allowTimeBooking?: boolean | undefined, articleId?: string | undefined, assignees?: Array | undefined, billableStatus?: boolean | undefined, calendarEventId?: string | undefined, createdDate?: number | undefined, creatorUserId?: string | undefined, customAttributes?: Array | undefined, customerId?: string | undefined, dateFrom?: number | undefined, dateTo?: number | undefined, description?: string | undefined, entityReferences?: Array | undefined, identifier?: string | undefined, invoicingStatus?: ('INVOICED' | 'NOT_INVOICED' | 'PARTLY_INVOICED') | undefined, lastModifiedDate?: number | undefined, lastReminderDateForOverdue?: number | undefined, orderItemId?: string | undefined, parentTaskId?: string | undefined, performanceRecordedStatus?: ('NOT_PERFORMANCE_RECORDABLE' | 'ON_PERFORMANCE_RECORD' | 'PERFORMANCE_RECORDABLE' | 'PERFORMANCE_RECORDED') | undefined, plannedEffort?: number | undefined, positionNumber?: number | undefined, previousTaskId?: string | undefined, subject?: string | undefined, taskLists?: Array | undefined, taskMailAccount?: TaskMailAccount | undefined, taskPriority: 'HIGH' | 'LOW' | 'MEDIUM', taskStatus: 'COMPLETED' | 'DEFERRED' | 'IN_PROGRESS' | 'NOT_STARTED' | 'WAITING_ON_OTHERS', taskTopics?: Array | undefined, taskTypes?: Array | undefined, taskVisibilityType: 'ORGANIZATION' | 'PRIVATE', ticketId?: string | undefined, userOfLastStatusChangeId?: string | undefined, watchers?: Array | undefined}; export type UpdateApiTaskIdIdArgs = {id: string, dryRun?: boolean | undefined, body: Task}; export type UpdateApiTaskIdIdOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const taskAssignee = z.object({id: z.string().optional(), version: z.string().optional(), createdDate: z.number().int().optional(), lastModifiedDate: z.number().int().optional(), plannedEffort: z.number().int().optional(), userId: z.string().optional()}); export const entityReference = z.object({entityId: z.string().optional(), entityName: z.string().optional()}); export const onlyId = z.object({id: z.string().optional()}); export const customAttribute = z.object({attributeDefinitionId: z.string().optional(), booleanValue: z.boolean().optional(), dateValue: z.number().int().optional(), entityId: z.string().optional(), entityReferences: z.array(entityReference).optional(), numberValue: z.string().optional(), selectedValueId: z.string().optional(), selectedValues: z.array(onlyId).optional(), stringValue: z.string().optional()}); export const taskMailAccount = z.object({id: z.string().optional(), version: z.string().optional(), createdDate: z.number().int().optional(), lastModifiedDate: z.number().int().optional(), mailAccountId: z.string().optional(), serverIdentifier: z.string().optional()}); export const task = z.object({id: z.string().optional(), version: z.string().optional(), allowOverBooking: z.boolean().optional(), allowTimeBooking: z.boolean().optional(), articleId: z.string().optional(), assignees: z.array(taskAssignee).optional(), billableStatus: z.boolean().optional(), calendarEventId: z.string().optional(), createdDate: z.number().int().optional(), creatorUserId: z.string().optional(), customAttributes: z.array(customAttribute).optional(), customerId: z.string().optional(), dateFrom: z.number().int().optional(), dateTo: z.number().int().optional(), description: z.string().optional(), entityReferences: z.array(entityReference).optional(), identifier: z.string().optional(), invoicingStatus: z.enum(["INVOICED", "NOT_INVOICED", "PARTLY_INVOICED"]).optional(), lastModifiedDate: z.number().int().optional(), lastReminderDateForOverdue: z.number().int().optional(), orderItemId: z.string().optional(), parentTaskId: z.string().optional(), performanceRecordedStatus: z.enum(["NOT_PERFORMANCE_RECORDABLE", "ON_PERFORMANCE_RECORD", "PERFORMANCE_RECORDABLE", "PERFORMANCE_RECORDED"]).optional(), plannedEffort: z.number().int().optional(), positionNumber: z.number().int().optional(), previousTaskId: z.string().optional(), subject: z.string().optional(), taskLists: z.array(onlyId).optional(), taskMailAccount: taskMailAccount.optional(), taskPriority: z.enum(["HIGH", "LOW", "MEDIUM"]), taskStatus: z.enum(["COMPLETED", "DEFERRED", "IN_PROGRESS", "NOT_STARTED", "WAITING_ON_OTHERS"]), taskTopics: z.array(onlyId).optional(), taskTypes: z.array(onlyId).optional(), taskVisibilityType: z.enum(["ORGANIZATION", "PRIVATE"]), ticketId: z.string().optional(), userOfLastStatusChangeId: z.string().optional(), watchers: z.array(onlyId).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 task * * PUT /task/id/{id} */ export const updateApiTaskIdId = async (args: UpdateApiTaskIdIdArgs, options: UpdateApiTaskIdIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dryRun != null) query.append("dryRun", String(args.dryRun)) if (APIToken !== undefined) headers.set("AuthenticationToken", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/task/id/${encodeURIComponent(String(args.id))}${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(task, await res.json()) };