import {z} from 'zod' export type GetApiApi3AssetsIdServicesProtocolPortUsersArgs = {id: number, port: number, protocol: 'ip' | 'icmp' | 'igmp' | 'ggp' | 'tcp' | 'pup' | 'udp' | 'idp' | 'esp' | 'nd' | 'raw'}; export type GetApiApi3AssetsIdServicesProtocolPortUsersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const link = z.object({deprecation: z.string().optional(), href: z.string().optional(), hreflang: z.string().optional(), media: z.string().optional(), rel: z.string().optional(), title: z.string().optional(), type: z.string().optional()}); export const userAccount = z.object({fullName: z.string().optional(), id: z.number().int().optional(), name: z.string().optional()}); export const collectionModelUserAccount = z.object({links: z.array(link), resources: z.array(userAccount).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 }; /** * Asset Service Users * * GET /api/3/assets/{id}/services/{protocol}/{port}/users */ export const getApiApi3AssetsIdServicesProtocolPortUsers = async (args: GetApiApi3AssetsIdServicesProtocolPortUsersArgs, options?: GetApiApi3AssetsIdServicesProtocolPortUsersOptions) => { const {baseUrl = "https://:", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json;charset=UTF-8") const url = `${baseUrl.replace(/\/+$/, '')}/api/3/assets/${encodeURIComponent(String(args.id))}/services/${encodeURIComponent(String(args.protocol))}/${encodeURIComponent(String(args.port))}/users${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(collectionModelUserAccount, await res.json()) };