import {z} from 'zod' export type RoutingQueueCondition = {id?: number | undefined, queueId?: number | undefined, accountId?: number | undefined, filterType?: (string | null) | undefined, filterColumn?: (string | null) | undefined, filterOperation?: (string | null) | undefined, filterValue?: (string | null) | undefined, filterLevel?: number | undefined, filterLevelOperation?: (string | null) | undefined}; export type RoutingQueueAction = {id?: number | undefined, queueId?: number | undefined, accountId?: number | undefined, actionType?: (string | null) | undefined, groupId?: number | undefined, userId?: (number | null) | undefined, orderNo?: number | undefined}; export type RoutingQueue = {id?: number | undefined, accountId?: number | undefined, name: string, description?: (string | null) | undefined, departmentIds: string, linkedType?: number | undefined, eventType: string, assignMethod?: number | undefined, priority?: number | undefined, workingHourType?: number | undefined, workingHourId?: (number | null) | undefined, status?: boolean | undefined, createdDate?: string | undefined, updatedDate?: (string | null) | undefined, conditions?: (Array | null) | undefined, actions?: (Array | null) | undefined}; export type CreateApiV1RoutingQueuesArgs = {body: RoutingQueue}; export type CreateApiV1RoutingQueuesOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const routingQueueCondition = z.object({id: z.number().int().optional(), queueId: z.number().int().optional(), accountId: z.number().int().optional(), filterType: z.string().max(16).nullable().optional(), filterColumn: z.string().max(64).nullable().optional(), filterOperation: z.string().max(16).nullable().optional(), filterValue: z.string().max(512).nullable().optional(), filterLevel: z.number().int().optional(), filterLevelOperation: z.string().max(4).nullable().optional()}); export const routingQueueActionDetail = z.object({id: z.number().int().optional(), actionType: z.string().nullable().optional(), groupId: z.number().int().optional(), groupName: z.string().nullable().optional(), userId: z.number().int().nullable().optional(), userName: z.string().nullable().optional(), orderNo: z.number().int().optional()}); export const routingQueueDetail = z.object({id: z.number().int().optional(), name: z.string().nullable().optional(), description: z.string().nullable().optional(), departmentIds: z.string().nullable().optional(), linkedType: z.number().int().optional(), eventType: z.string().nullable().optional(), assignMethod: z.number().int().optional(), priority: z.number().int().optional(), workingHourType: z.number().int().optional(), workingHourId: z.number().int().nullable().optional(), status: z.boolean().optional(), createdDate: z.string().optional(), updatedDate: z.string().nullable().optional(), conditions: z.array(routingQueueCondition).nullable().optional(), actions: z.array(routingQueueActionDetail).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/routing-queues * * Also accepts auth: API Key */ export const createApiV1RoutingQueues = async (args: CreateApiV1RoutingQueuesArgs, options: CreateApiV1RoutingQueuesOptions) => { 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/routing-queues${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(routingQueueDetail, await res.json()) };