import {z} from 'zod' export type OnlyId = {id?: string | undefined}; export type TicketServiceLevelAgreementTarget = {assignmentTimeQuantity?: number | undefined, assignmentTimeUnit?: ('DAYS' | 'HOURS' | 'MINUTES' | 'NONE') | undefined, businessHolidaysId?: number | undefined, firstReplyTimeQuantity?: number | undefined, firstReplyTimeUnit?: ('DAYS' | 'HOURS' | 'MINUTES' | 'NONE') | undefined, notification?: boolean | undefined, priorityId?: string | undefined, sendEscalationEmail?: boolean | undefined, solutionTimeQuantity?: number | undefined, solutionTimeUnit?: ('DAYS' | 'HOURS' | 'MINUTES' | 'NONE') | undefined, workScheduleProfileId?: string | undefined}; export type TicketServiceLevelAgreement = {id?: string | undefined, version?: string | undefined, active?: boolean | undefined, categories?: Array | undefined, createdDate?: number | undefined, customers?: Array | undefined, includeNoTicketType?: boolean | undefined, lastModifiedDate?: number | undefined, name: string, ratingId?: string | undefined, targets?: Array | undefined, types?: Array | undefined}; export type CreateApiTicketServiceLevelAgreementArgs = {dryRun?: boolean | undefined, body: TicketServiceLevelAgreement}; export type CreateApiTicketServiceLevelAgreementOptions = {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 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 }; /** * create a ticketServiceLevelAgreement * * POST /ticketServiceLevelAgreement */ export const createApiTicketServiceLevelAgreement = async (args: CreateApiTicketServiceLevelAgreementArgs, options: CreateApiTicketServiceLevelAgreementOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dryRun != null) query.append("dryRun", String(args.dryRun)) if (APIToken !== undefined) headers.set("AuthenticationToken", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/ticketServiceLevelAgreement${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(ticketServiceLevelAgreement, await res.json()) };