import {z} from 'zod' export type CreateApiHotdeskingArgs = {body: {extension_number: string, extension_password: string, display_name?: string | undefined, mac: string, filename: string, vendor: string, model: string, password: string, language: 'ENGLISH' | 'CHINESE' | 'DUTCH' | 'FRENCH' | 'GERMAN' | 'GREEK' | 'ITALIAN' | 'JAPANESE' | 'POLISH' | 'RUSSIAN' | 'SPANISH' | 'SWEDISH' | 'UKRAINIAN' | 'BULGARIAN', transfer: 'BLIND' | 'ATTENDED' | 'NEW_CALL', timezone: string, ringtone?: string | undefined, queue_ringtone?: string | undefined, external_ringtone?: string | undefined, date_format?: string | undefined, time_format?: string | undefined, powerled?: string | undefined, backlight?: string | undefined, screensaver?: string | undefined, rps?: boolean | undefined, https?: boolean | undefined, codecs: Array, enable_lldp?: boolean | undefined, enable_vlan_wan_port?: boolean | undefined, wan_port_id?: number | undefined, wan_port_priority?: number | undefined, enable_vlan_pc_port?: boolean | undefined, pc_port_id?: number | undefined, pc_port_priority?: number | undefined, interface: 'WEB_DOMAIN' | 'PUBLIC_IPV4' | 'PUBLIC_IPV6' | 'PRIVATE_IPV4' | 'PRIVATE_IPV6' | 'SBC_DOMAIN', preferred_transport: 'UDP' | 'TCP' | 'TLS', serial_number?: string | undefined}}; export type CreateApiHotdeskingOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiHotdeskingResponse = z.object({id: z.string().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 hot desking device. * * POST /hotdesking */ export const createApiHotdesking = async (args: CreateApiHotdeskingArgs, options?: CreateApiHotdeskingOptions) => { const {baseUrl = "https://HOSTNAME:8887/api", 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(/\/+$/, '')}/hotdesking${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(createApiHotdeskingResponse, await res.json()) };