import {z} from 'zod' export type GetApiApiV2TicketMetricsTicketMetricIdArgs = {'page[before]'?: string | undefined, 'page[after]'?: string | undefined, 'page[size]'?: number | undefined, ticket_metric_id: string}; export type GetApiApiV2TicketMetricsTicketMetricIdOptions = {baseUrl?: string | undefined, apiTokenAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const ticketMetricTimeObject = z.object({business: z.number().int().optional(), calendar: z.number().int().optional()}); export const ticketMetricObject = z.object({agent_wait_time_in_minutes: ticketMetricTimeObject.optional(), assigned_at: z.string().optional(), assignee_stations: z.number().int().optional(), assignee_updated_at: z.string().optional(), created_at: z.string().optional(), custom_status_updated_at: z.string().optional(), first_resolution_time_in_minutes: ticketMetricTimeObject.optional(), full_resolution_time_in_minutes: ticketMetricTimeObject.optional(), group_stations: z.number().int().optional(), id: z.number().int().optional(), initially_assigned_at: z.string().optional(), latest_comment_added_at: z.string().optional(), on_hold_time_in_minutes: ticketMetricTimeObject.optional(), reopens: z.number().int().optional(), replies: z.number().int().optional(), reply_time_in_minutes: ticketMetricTimeObject.optional(), reply_time_in_seconds: ticketMetricTimeObject.optional(), requester_updated_at: z.string().optional(), requester_wait_time_in_minutes: ticketMetricTimeObject.optional(), solved_at: z.string().optional(), status_updated_at: z.string().optional(), ticket_id: z.number().int().optional(), updated_at: z.string().optional(), url: z.string().optional()}); export const ticketMetricsByTicketMetricIdResponse = z.object({ticket_metric: z.array(ticketMetricObject).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 }; /** * Show Ticket Metrics * * GET /api/v2/ticket_metrics/{ticket_metric_id} */ export const getApiApiV2TicketMetricsTicketMetricId = async (args: GetApiApiV2TicketMetricsTicketMetricIdArgs, options?: GetApiApiV2TicketMetricsTicketMetricIdOptions) => { const {baseUrl = "https://example.zendesk.com", fetch: fetchFn = fetch, apiTokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['page[before]'] != null) query.append("page[before]", String(args['page[before]'])) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (apiTokenAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${apiTokenAuth.username}:${apiTokenAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/ticket_metrics/${encodeURIComponent(String(args.ticket_metric_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(ticketMetricsByTicketMetricIdResponse, await res.json()) };