import {z} from 'zod' export type GetApiV2TicketingTicketTicketIdLogEntryArgs = {ticketId: number, type?: (Array<'DESCRIPTION' | 'COMMENT' | 'CONDITION' | 'SAVE' | 'DELETE' | 'PRODUCT' | 'INFO'>) | undefined, createTime?: string | undefined, anchorId?: number | undefined, pageSize?: number | undefined}; export type GetApiV2TicketingTicketTicketIdLogEntryOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2TicketingTicketTicketIdLogEntryResponse = z.array(z.object({id: z.number().int().optional(), appUserContactUid: z.string().optional(), appUserContactId: z.number().int().optional(), appUserContactType: z.enum(["TECHNICIAN", "END_USER", "CONTACT"]).optional(), type: z.enum(["DESCRIPTION", "COMMENT", "CONDITION", "SAVE", "DELETE", "PRODUCT", "INFO"]).optional(), body: z.string().optional(), htmlBody: z.string().optional(), fullEmailBody: z.string().optional(), publicEntry: z.boolean().optional(), system: z.boolean().optional(), createTime: z.number().optional(), changeDiff: z.object({}).optional(), activityId: z.number().int().optional(), timeTracked: z.number().int().optional(), technicianTagged: z.array(z.number().int()).optional(), techniciansTaggedMetadata: z.array(z.object({id: z.number().int().optional(), email: z.string().optional(), displayName: z.string().optional(), deleted: z.boolean().optional(), permitted: z.boolean().optional()})).optional(), automation: z.object({id: z.number().int().optional(), name: z.string().optional(), system: z.boolean().optional(), type: z.string().optional()}).optional(), ticketTimeEntry: z.object({ticketLogEntryId: z.number().int().optional(), startDate: z.number().int().optional(), remote: z.boolean().optional(), timeTracked: z.number().int().optional(), inHours: z.object({price: z.number().optional(), timeTracked: z.number().int().optional(), billing: z.enum(["BILLABLE", "NOT_BILLABLE", "NO_CHARGE"]).optional(), billingStatus: z.enum(["BILLED", "PENDING", "NOT_BILLABLE", "UNASSIGNED"]).optional(), agreementOriginType: z.enum(["NONE", "SELF", "TICKET"]).optional(), agreementProduct: z.object({id: z.number().int().optional(), name: z.string().optional()}).optional(), agreement: z.object({id: z.number().int().optional(), name: z.string().optional()}).optional(), invoiceId: z.number().int().optional()}).optional(), offHours: z.object({price: z.number().optional(), timeTracked: z.number().int().optional(), billing: z.enum(["BILLABLE", "NOT_BILLABLE", "NO_CHARGE"]).optional(), billingStatus: z.enum(["BILLED", "PENDING", "NOT_BILLABLE", "UNASSIGNED"]).optional(), agreementOriginType: z.enum(["NONE", "SELF", "TICKET"]).optional(), agreementProduct: z.object({id: z.number().int().optional(), name: z.string().optional()}).optional(), agreement: z.object({id: z.number().int().optional(), name: z.string().optional()}).optional(), invoiceId: z.number().int().optional()}).optional()}).optional(), emailResponse: 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 }; /** * List ticket log entries * * GET /v2/ticketing/ticket/{ticketId}/log-entry * * Also accepts auth: sessionKey */ export const getApiV2TicketingTicketTicketIdLogEntry = async (args: GetApiV2TicketingTicketTicketIdLogEntryArgs, options: GetApiV2TicketingTicketTicketIdLogEntryOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.type ?? []) query.append("type", String(item)) if (args.createTime != null) query.append("createTime", String(args.createTime)) if (args.anchorId != null) query.append("anchorId", String(args.anchorId)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/ticketing/ticket/${encodeURIComponent(String(args.ticketId))}/log-entry${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(getApiV2TicketingTicketTicketIdLogEntryResponse, await res.json()) };