import {z} from 'zod' export type AssignTicketReviewerRequest = {assignee_email: string | null}; export type CreateApiTicketsTicketIdAssignArgs = {ticket_id: string, body: AssignTicketReviewerRequest}; export type CreateApiTicketsTicketIdAssignOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const assignTicketReviewerResponse = z.object({ticket_id: z.string().optional(), target_id: z.string().optional(), target_id_type: z.enum(["USER", "USER_PROFILE", "BUSINESS", "null"]).nullable().optional(), ticket_status: z.enum(["OPEN", "RESOLVED"]).optional(), trigger: z.string().nullable().optional(), review_queue: z.object({review_queue_id: z.string().optional(), name: z.string().optional()}).nullable().optional(), assignee: z.object({email: z.string().optional()}).nullable().optional(), created_at: z.number().int().optional(), resolved_at: z.number().int().nullable().optional(), updated: 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 }; /** * Assign Ticket Reviewer * * POST /tickets/{ticket_id}/assign */ export const createApiTicketsTicketIdAssign = async (args: CreateApiTicketsTicketIdAssignArgs, options?: CreateApiTicketsTicketIdAssignOptions) => { const {baseUrl = "https://api-sandbox.aiprise.com/api/v1", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("X-API-KEY", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/tickets/${encodeURIComponent(String(args.ticket_id))}/assign${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(assignTicketReviewerResponse, await res.json()) };