import {z} from 'zod' export type TaskRecurrenceInfo = {schedule?: ('None' | 'Daily' | 'Weekdays' | 'Weekly' | 'Monthly' | 'Yearly') | undefined, endingCondition?: ('None' | 'Count' | 'Date') | undefined, endingAfter?: number | undefined, endingOn?: string | undefined}; export type TMAttachmentInfo = {id?: string | undefined, type?: ('File' | 'Note' | 'Event' | 'Card') | undefined}; export type TMUpdateTaskRequest = {subject?: string | undefined, assignees?: (Array<{id?: string | undefined}>) | undefined, completenessCondition?: ('Simple' | 'AllAssignees' | 'Percentage') | undefined, startDate?: string | undefined, dueDate?: string | undefined, color?: ('Black' | 'Red' | 'Orange' | 'Yellow' | 'Green' | 'Blue' | 'Purple' | 'Magenta') | undefined, section?: string | undefined, description?: string | undefined, recurrence?: TaskRecurrenceInfo | undefined, attachments?: Array | undefined}; export type PatchApiTeamMessagingV1TasksTaskIdArgs = {taskId: string, body: TMUpdateTaskRequest}; export type PatchApiTeamMessagingV1TasksTaskIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const taskRecurrenceInfo = z.object({schedule: z.enum(["None", "Daily", "Weekdays", "Weekly", "Monthly", "Yearly"]).optional(), endingCondition: z.enum(["None", "Count", "Date"]).optional(), endingAfter: z.number().int().gte(1).lte(10).optional(), endingOn: z.string().optional()}); export const taskAttachment = z.object({id: z.string().optional(), type: z.literal("File").optional(), name: z.string().optional(), contentUri: z.string().optional()}); export const tMTaskInfo = z.object({id: z.string().optional(), creationTime: z.string().optional(), lastModifiedTime: z.string().optional(), type: z.literal("Task").optional(), creator: z.object({id: z.string().optional()}).optional(), chatIds: z.array(z.string()).optional(), status: z.enum(["Pending", "InProgress", "Completed"]).optional(), subject: z.string().optional(), assignees: z.array(z.object({id: z.string().optional(), status: z.enum(["Pending", "Completed"]).optional()})).optional(), completenessCondition: z.enum(["Simple", "AllAssignees", "Percentage"]).optional(), completenessPercentage: z.number().int().gte(0).lte(100).optional(), startDate: z.string().optional(), dueDate: z.string().optional(), color: z.enum(["Black", "Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Magenta"]).optional(), section: z.string().optional(), description: z.string().optional(), recurrence: taskRecurrenceInfo.optional(), attachments: z.array(taskAttachment).optional()}); export const tMNavigationInfo = z.object({prevPageToken: z.string().optional(), nextPageToken: z.string().optional()}); export const tMTaskList = z.object({records: z.array(tMTaskInfo).optional(), navigation: tMNavigationInfo.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 * * PATCH /team-messaging/v1/tasks/{taskId} */ export const patchApiTeamMessagingV1TasksTaskId = async (args: PatchApiTeamMessagingV1TasksTaskIdArgs, options?: PatchApiTeamMessagingV1TasksTaskIdOptions) => { const {baseUrl = "https://platform.ringcentral.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/team-messaging/v1/tasks/${encodeURIComponent(String(args.taskId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(tMTaskList, await res.json()) };