import {z} from 'zod' export type UpdateApiV2TicketingTicketTicketIdArgs = {ticketId: number, body: {version: number, clientId: number, ticketFormId: number, locationId?: (number | null) | undefined, nodeId?: (number | null) | undefined, subject: string, status: string, type?: ('PROBLEM' | 'QUESTION' | 'INCIDENT' | 'TASK' | 'CHANGE_REQUEST' | 'SERVICE_REQUEST' | 'PROJECT' | 'APPOINTMENT' | 'MISCELLANEOUS' | null) | undefined, cc?: ({uids?: (Array | null) | undefined, emails?: (Array | null) | undefined} | null) | undefined, assignedAppUserId?: (number | null) | undefined, requesterUid: string, severity?: ('NONE' | 'MINOR' | 'MODERATE' | 'MAJOR' | 'CRITICAL' | null) | undefined, priority?: ('NONE' | 'LOW' | 'MEDIUM' | 'HIGH' | null) | undefined, parentTicketId?: (number | null) | undefined, tags?: (Array | null) | undefined, attributes?: (Array<{id?: (number | null) | undefined, attributeId: number, value: string} | null> | null) | undefined, additionalAssignedTechnicianIds?: (Array | null) | undefined, followupTime?: (number | null) | undefined}}; export type UpdateApiV2TicketingTicketTicketIdOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV2TicketingTicketTicketIdResponse = z.object({id: z.number().int().optional(), version: z.number().int().optional(), nodeId: z.number().int().optional(), clientId: z.number().int().optional(), locationId: z.number().int().optional(), assignedAppUserId: z.number().int().optional(), requesterUid: z.string().optional(), subject: z.string().optional(), status: z.object({name: z.string().optional(), displayName: z.string().optional(), parentId: z.number().int().optional(), statusId: z.number().int().optional()}).optional(), type: z.enum(["PROBLEM", "QUESTION", "INCIDENT", "TASK", "CHANGE_REQUEST", "SERVICE_REQUEST", "PROJECT", "APPOINTMENT", "MISCELLANEOUS"]).optional(), priority: z.enum(["NONE", "LOW", "MEDIUM", "HIGH"]).optional(), severity: z.enum(["NONE", "MINOR", "MODERATE", "MAJOR", "CRITICAL"]).optional(), ticketFormId: z.number().int().optional(), source: z.enum(["TECHNICIAN", "EMAIL", "WEB_FORM", "HELP_REQUEST", "END_USER", "CONDITION", "SCHEDULED_SCRIPT", "ACTIVITY"]).optional(), tags: z.array(z.string()).optional(), ccList: z.object({uids: z.array(z.string()).optional(), emails: z.array(z.string()).optional()}).optional(), createTime: z.number().optional(), deleted: z.boolean().optional(), attributeValues: z.array(z.object({id: z.number().int().optional(), attributeId: z.number().int().optional(), value: z.object({}).optional()})).optional(), additionalAssignedTechnicianIds: z.array(z.number().int()).optional(), followupTime: z.number().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 ticket * * PUT /v2/ticketing/ticket/{ticketId} * * Also accepts auth: sessionKey */ export const updateApiV2TicketingTicketTicketId = async (args: UpdateApiV2TicketingTicketTicketIdArgs, options: UpdateApiV2TicketingTicketTicketIdOptions) => { const {baseUrl, 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(/\/+$/, '')}/v2/ticketing/ticket/${encodeURIComponent(String(args.ticketId))}${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(updateApiV2TicketingTicketTicketIdResponse, await res.json()) };