import {z} from 'zod' export type TicketSource = 1 | 2 | 3 | 4 | 5 | 6; export type TicketStatus = 1 | 2 | 3 | 4; export type PriorityType = 1 | 2 | 3 | 4; export type Table = 0 | 1 | 2 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 55 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 72; export type SlaStats = {id?: number | undefined, departmentId?: number | undefined, slaId?: number | undefined, linkedType?: number | undefined, linkedId?: number | undefined, dueBy?: (string | null) | undefined, resolveTime?: (string | null) | undefined, dueEscalated?: boolean | undefined, frDueBy?: (string | null) | undefined, frTime?: (string | null) | undefined, frEscalated?: boolean | undefined, nrDueBy?: (string | null) | undefined, nrTime?: (string | null) | undefined, nrEscalated?: boolean | undefined, accountId?: number | undefined}; export type TicketResponseModel = {id?: (number | null) | undefined, subject?: (string | null) | undefined, departmentId?: (number | null) | undefined, pipelineId?: (number | null) | undefined, stageId?: (number | null) | undefined, orderNo?: (number | null) | undefined, contactId?: (number | null) | undefined, contactName?: (string | null) | undefined, contactEmail?: (string | null) | undefined, contactPhone?: (string | null) | undefined, companyId?: (number | null) | undefined, companyName?: (string | null) | undefined, categoryIds?: (string | null) | undefined, categoryNames?: (string | null) | undefined, ownerIds?: (string | null) | undefined, ownerGroupId?: (number | null) | undefined, ownerNames?: (string | null) | undefined, ownerPhotos?: (string | null) | undefined, ownerColors?: (string | null) | undefined, followerIds?: (string | null) | undefined, startDate?: (string | null) | undefined, dueDate?: (string | null) | undefined, source?: TicketSource | undefined, status?: TicketStatus | undefined, lastStatusChangeDate?: (string | null) | undefined, priority?: PriorityType | undefined, createdUserId?: (number | null) | undefined, createdDate?: (string | null) | undefined, updatedUserId?: (number | null) | undefined, updatedDate?: (string | null) | undefined, notes?: (string | null) | undefined, linkedType?: Table | undefined, linkedId?: (number | null) | undefined, linked?: (string | null) | undefined, customFields?: (string | null) | undefined, firstResponseDate?: (string | null) | undefined, closingDate?: (string | null) | undefined, reopenDate?: (string | null) | undefined, resolveTimeSec?: (number | null) | undefined, resolveTimeBusinessSec?: (number | null) | undefined, frTimeSec?: (number | null) | undefined, frTimeBusinessSec?: (number | null) | undefined, openTimeSec?: (number | null) | undefined, openTimeBusinessSec?: (number | null) | undefined, pendingTimeSec?: (number | null) | undefined, pendingTimeBusinessSec?: (number | null) | undefined, isSpam?: (number | null) | undefined, slaId?: (number | null) | undefined, nextSlaBreach?: (string | null) | undefined, slaStats?: SlaStats | undefined, highlights?: ({[key: string]: Array | null} | null) | undefined}; export type CreateApiV1TicketsInsertbulkArgs = {body: Array}; export type CreateApiV1TicketsInsertbulkOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const insertBulkError = z.object({row: z.number().int().optional(), error: z.string().nullable().optional()}); export const insertBulkResponse = z.object({inserted: z.number().int().optional(), updated: z.number().int().optional(), errors: z.array(insertBulkError).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 }; /** * POST /v1/tickets/insertbulk * * Also accepts auth: API Key */ export const createApiV1TicketsInsertbulk = async (args: CreateApiV1TicketsInsertbulkArgs, options: CreateApiV1TicketsInsertbulkOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/tickets/insertbulk${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(insertBulkResponse, await res.json()) };