import {z} from 'zod' export type GetApiV1SwitchNodesetLldpArgs = {ports?: string | undefined, Accept?: string | undefined, nodeset: string}; export type GetApiV1SwitchNodesetLldpOptions = {baseUrl?: string | undefined, headerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const lLDP = z.object({chassis_id: z.string().optional(), chassis_id_type: z.string().optional(), management_address: z.string().optional(), port_description: z.string().optional(), port_id: z.string().optional(), port_id_type: z.string().optional(), port_name: z.string().optional(), system_description: z.string().optional(), system_name: z.string().optional()}); export const getApiV1SwitchNodesetLldpResponse = z.array(lLDP); 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 }; /** * switch get l l d p * * GET /v1/switch/{nodeset}/lldp * * Also accepts auth: cookieAuth */ export const getApiV1SwitchNodesetLldp = async (args: GetApiV1SwitchNodesetLldpArgs, options?: GetApiV1SwitchNodesetLldpOptions) => { const {baseUrl = "https://127.0.0.1:8080", fetch: fetchFn = fetch, headerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ports != null) query.append("ports", String(args.ports)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (headerAuth !== undefined) headers.set('authorization', `Bearer ${headerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/switch/${encodeURIComponent(String(args.nodeset))}/lldp${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(getApiV1SwitchNodesetLldpResponse, await res.json()) };