import {z} from 'zod' export type GetApiServiceTenantNameBgpRouteMapRuleNameArgs = {tenant_name: unknown, name: unknown}; export type GetApiServiceTenantNameBgpRouteMapRuleNameOptions = {baseUrl: string, HTTPBearerFromCookie?: string | undefined, fetch?: typeof fetch | undefined}; export const routeMapAction = z.enum(["permit", "deny"]); export const pfxListItem = z.object({ip: z.string(), le: z.number().int().nullable().optional(), ge: z.number().int().nullable().optional(), seq: z.number().int().nullable().optional(), match: z.boolean().optional()}); export const bGPRouteMapRule = z.object({id: z.number().int(), route_map_id: z.number().int(), name: z.string(), tenant_name: z.string().nullable().optional(), action: routeMapAction, priority: z.number().int(), filters: z.array(pfxListItem).optional(), description: z.string().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 }; /** * Get Tenant Bgp Route Map Rule * * GET /service/{tenant_name}/bgp_route_map_rule/{name} */ export const getApiServiceTenantNameBgpRouteMapRuleName = async (args: GetApiServiceTenantNameBgpRouteMapRuleNameArgs, options: GetApiServiceTenantNameBgpRouteMapRuleNameOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearerFromCookie} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearerFromCookie !== undefined) headers.set('authorization', `Bearer ${HTTPBearerFromCookie}`) const url = `${baseUrl.replace(/\/+$/, '')}/service/${encodeURIComponent(String(args.tenant_name))}/bgp_route_map_rule/${encodeURIComponent(String(args.name))}${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(bGPRouteMapRule, await res.json()) };