import {z} from 'zod' export type GetApiTicketServiceLevelAgreementArgs = {page?: number | undefined, pageSize?: number | undefined, sort?: string | undefined}; export type GetApiTicketServiceLevelAgreementOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const onlyId = z.object({id: z.string().optional()}); export const ticketServiceLevelAgreementTarget = z.object({assignmentTimeQuantity: z.number().int().optional(), assignmentTimeUnit: z.enum(["DAYS", "HOURS", "MINUTES", "NONE"]).optional(), businessHolidaysId: z.number().int().optional(), firstReplyTimeQuantity: z.number().int().optional(), firstReplyTimeUnit: z.enum(["DAYS", "HOURS", "MINUTES", "NONE"]).optional(), notification: z.boolean().optional(), priorityId: z.string().optional(), sendEscalationEmail: z.boolean().optional(), solutionTimeQuantity: z.number().int().optional(), solutionTimeUnit: z.enum(["DAYS", "HOURS", "MINUTES", "NONE"]).optional(), workScheduleProfileId: z.string().optional()}); export const ticketServiceLevelAgreement = z.object({id: z.string().optional(), version: z.string().optional(), active: z.boolean().optional(), categories: z.array(onlyId).optional(), createdDate: z.number().int().optional(), customers: z.array(onlyId).optional(), includeNoTicketType: z.boolean().optional(), lastModifiedDate: z.number().int().optional(), name: z.string(), ratingId: z.string().optional(), targets: z.array(ticketServiceLevelAgreementTarget).optional(), types: z.array(onlyId).optional()}); export const getApiTicketServiceLevelAgreementResponse = z.object({result: z.array(ticketServiceLevelAgreement).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 }; /** * query ticketServiceLevelAgreement * * GET /ticketServiceLevelAgreement */ export const getApiTicketServiceLevelAgreement = async (args: GetApiTicketServiceLevelAgreementArgs, options: GetApiTicketServiceLevelAgreementOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.sort != null) query.append("sort", String(args.sort)) if (APIToken !== undefined) headers.set("AuthenticationToken", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/ticketServiceLevelAgreement${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(getApiTicketServiceLevelAgreementResponse, await res.json()) };