import {z} from 'zod' export type GetApiV1TicketsIdArgs = {id: number}; export type GetApiV1TicketsIdOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const revAppComponentsLink = z.object({rel: z.string().optional(), href: z.string().optional()}); export const revAppModelsFieldValue = z.object({field_id: z.number().int().optional(), label: z.string().optional(), value: z.string().optional(), links: z.array(revAppComponentsLink).optional()}); export const revWebAPIModelsGetOrSearchOfRevAppModelsTicket = z.object({ok: z.boolean().optional(), ticket_id: z.number().int().gte(0).lte(2147483647).optional(), description: z.string().min(1).max(2147483647).optional(), status: z.enum(["OPEN", "INWORK", "CLOSED", "PENDING_CANCELLATION", "CANCELED", "PENDING_CLOSE", "PENDING"]).optional(), resolution: z.string().max(2147483647).optional(), ticket_type_id: z.number().int().gte(1).lte(2147483647).optional(), ticket_step_id: z.number().int().gte(0).lte(2147483647).optional(), assigned_user_id: z.number().int().gte(0).lte(2147483647).optional(), assigned_group_id: z.number().int().gte(0).lte(2147483647).optional(), customer_id: z.number().int().gte(0).lte(2147483647).optional(), service_id: z.number().int().gte(0).lte(2147483647).optional(), priority_id: z.number().int().gte(1).lte(2147483647).optional(), contact_name: z.string().min(1).max(512).optional(), contact_phone: z.string().min(7).max(50).optional(), contact_email: z.string().min(1).max(255).optional(), additional_contact_emails: z.string().optional(), admin_ccs: z.string().optional(), custom_status: z.string().min(1).max(150).optional(), due_date: z.string().optional(), created_date: z.string().optional(), closed_date: z.string().optional(), created_by: z.number().int().gte(0).lte(2147483647).optional(), fields: z.array(revAppModelsFieldValue).optional(), modified_date: z.string().optional(), modified_by: z.number().int().gte(0).lte(2147483647).optional(), process_id: z.number().int().optional(), contact_id: z.number().int().optional(), provider_ticket_number: z.string().max(50).optional(), provider_contact_ID: z.number().int().optional(), process_phase_id: z.number().int().optional(), creation_source: z.string().optional(), links: z.array(revAppComponentsLink).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 }; /** * View ticket * * GET /v1/Tickets/{id} */ export const getApiV1TicketsId = async (args: GetApiV1TicketsIdArgs, options?: GetApiV1TicketsIdOptions) => { const {baseUrl = "https://restapi.rev.io", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Tickets/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(revWebAPIModelsGetOrSearchOfRevAppModelsTicket, await res.json()) };