import {z} from 'zod' export type GetApiApiV4UsersDeletedArgs = {limit?: number | undefined, offset?: number | undefined, name?: string | undefined, email?: string | undefined, sip_account?: string | undefined, security_access_group_id?: number | undefined, caller_id?: string | undefined, timezone?: string | undefined}; export type GetApiApiV4UsersDeletedOptions = {baseUrl: string, StaticKey?: string | undefined, fetch?: typeof fetch | undefined}; export const securityAccessGroupShort = z.object({id: z.number().int().optional(), name: z.string().optional()}); export const teamShort = z.object({id: z.number().int().optional(), name: z.string().optional()}); export const queueShort = z.object({id: z.number().int().optional(), name: z.string().optional()}); export const mediaRingtone = z.object({type: z.literal("ringtone").optional(), name: z.string().optional()}); export const channelProfileShort = z.object({id: z.number().int().optional(), channel: z.enum(["chat", "facebook", "instagram", "telegram", "viber", "whatsapp"]).optional(), identifier: z.string().nullable().optional(), name: z.string().optional()}); export const skill = z.object({id: z.number().int().optional(), name: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const user = z.object({id: z.number().int().optional(), name: z.string().optional(), email: z.string().optional(), sip_account: z.string().optional(), extension: z.string().nullable().optional(), caller_id: z.string().nullable().optional(), employee_id: z.string().nullable().optional(), timezone: z.string().optional(), security_access_group: securityAccessGroupShort.nullable().optional(), teams: z.array(teamShort).optional(), supervised_teams: z.array(teamShort).optional(), queues: z.array(queueShort).optional(), supervised_queues: z.array(queueShort).optional(), webrtc_ringtone: mediaRingtone.nullable().optional(), channels: z.array(z.enum(["chat", "facebook", "instagram", "telegram", "viber", "voice", "whatsapp"])).optional(), channel_group_capacity: z.object({chat: z.number().int().gte(0).optional(), instant: z.number().int().gte(0).optional()}).optional(), channel_profiles: z.array(channelProfileShort).optional(), speech_language: z.enum(["ar", "auto", "cs", "de", "en", "es", "fr", "hi", "hu", "it", "ja", "lt", "lv", "nl", "pl", "pt", "ro", "sk", "tr"]).nullable().optional(), skills: z.array(z.object({skill: skill.optional(), value: z.number().int().gte(1).lte(10).optional()})).optional(), voicemail_playback_enabled: z.boolean().optional(), status: z.enum(["offline", "unavailable", "available", "inbound", "outbound", "dialer", "postcall"]).optional(), created_at: z.string().optional(), updated_at: z.string().optional(), deleted_at: z.string().nullable().optional()}); export const metadata = z.object({total: z.number().int().optional(), next_cursor: z.string().nullable().optional()}); export const getApiApiV4UsersDeletedResponse = z.object({users: z.array(user).optional(), metadata: metadata.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 }; /** * Get list of deleted users * * GET /api/v4/users/deleted */ export const getApiApiV4UsersDeleted = async (args: GetApiApiV4UsersDeletedArgs, options: GetApiApiV4UsersDeletedOptions) => { const {baseUrl, fetch: fetchFn = fetch, StaticKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.name != null) query.append("name", String(args.name)) if (args.email != null) query.append("email", String(args.email)) if (args.sip_account != null) query.append("sip_account", String(args.sip_account)) if (args.security_access_group_id != null) query.append("security_access_group_id", String(args.security_access_group_id)) if (args.caller_id != null) query.append("caller_id", String(args.caller_id)) if (args.timezone != null) query.append("timezone", String(args.timezone)) if (StaticKey !== undefined) headers.set('authorization', `Bearer ${StaticKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v4/users/deleted${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(getApiApiV4UsersDeletedResponse, await res.json()) };