import {z} from 'zod' export type GetApiApiMobileDevicesArgs = {Authorization?: string | undefined, 'Credimi-Api-Key'?: string | undefined}; export type GetApiApiMobileDevicesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const handlersMobileDeviceListItem = z.object({description: z.string().optional(), is_online: z.boolean().optional(), is_owned: z.boolean().optional(), is_published: z.boolean().optional(), name: z.string().optional(), path: z.string().optional(), queue_length: z.number().int().nullable().optional(), runner_id: z.string().optional(), runner_name: z.string().optional(), serial: z.string().optional(), type: z.string().optional()}); export const handlersListMobileDevicesPublicResponseSchema = z.object({devices: z.array(handlersMobileDeviceListItem).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 }; /** * List available mobile devices * * GET /api/mobile-devices */ export const getApiApiMobileDevices = async (args: GetApiApiMobileDevicesArgs, options?: GetApiApiMobileDevicesOptions) => { const {baseUrl = "https://credimi.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args['Credimi-Api-Key'] != null) headers.set("Credimi-Api-Key", String(args['Credimi-Api-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/mobile-devices${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(handlersListMobileDevicesPublicResponseSchema, await res.json()) };