import {z} from 'zod' export type ViewType = 0 | 1; export type GetApiV1TicketsLogsArgs = {Id?: number | undefined, TicketId?: number | undefined, FromDate?: string | undefined, ToDate?: string | undefined, ItemsPerPage?: number | undefined, ViewType?: ViewType | undefined, Page?: number | undefined, ReturnTotalItems?: boolean | undefined}; export type GetApiV1TicketsLogsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const userReactionResponseModel = z.object({reactionId: z.number().int().optional(), reaction: z.string().nullable().optional(), userId: z.number().int().optional()}); export const ticketStatus = z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]); export const dealTicketLogMetadata = z.object({event: z.string().nullable().optional(), previousValue: z.string().max(200).nullable().optional(), value: z.string().max(200).nullable().optional(), extra: z.string().max(100).nullable().optional()}); export const ticketLogResponseModel = z.object({id: z.number().int().optional(), ticketId: z.number().int().optional(), pipelineId: z.number().int().optional(), stageId: z.number().int().optional(), createdUserId: z.number().int().optional(), createdContactId: z.number().int().optional(), createdAutomationId: z.number().int().optional(), createdDate: z.string().optional(), notes: z.string().nullable().optional(), reactions: z.array(userReactionResponseModel).nullable().optional(), isPrivate: z.number().int().optional(), status: ticketStatus.optional(), callLogId: z.number().int().optional(), chatRoomId: z.number().int().optional(), chatId: z.number().int().optional(), emailId: z.number().int().optional(), emailFileNames: z.string().nullable().optional(), emailFileLinks: z.string().nullable().optional(), emailFileSizes: z.string().nullable().optional(), smsLogId: z.number().int().optional(), pinDate: z.string().nullable().optional(), metadata: dealTicketLogMetadata.optional()}); export const ticketLogResponseModelQueryResult = z.object({totalItems: z.number().int().optional(), items: z.array(ticketLogResponseModel).nullable().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 }; /** * Returns the ticket logs of a ticket * * GET /v1/tickets/logs * * Also accepts auth: API Key */ export const getApiV1TicketsLogs = async (args: GetApiV1TicketsLogsArgs, options: GetApiV1TicketsLogsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Id != null) query.append("Id", String(args.Id)) if (args.TicketId != null) query.append("TicketId", String(args.TicketId)) if (args.FromDate != null) query.append("FromDate", String(args.FromDate)) if (args.ToDate != null) query.append("ToDate", String(args.ToDate)) if (args.ItemsPerPage != null) query.append("ItemsPerPage", String(args.ItemsPerPage)) if (args.ViewType != null) query.append("ViewType", String(args.ViewType)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.ReturnTotalItems != null) query.append("ReturnTotalItems", String(args.ReturnTotalItems)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/tickets/logs${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(ticketLogResponseModelQueryResult, await res.json()) };