import {z} from 'zod' export type GetApiApiV1ApplicationsApplicationNameResourceTreeArgs = {applicationName: string}; export type GetApiApiV1ApplicationsApplicationNameResourceTreeOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1alpha1HealthStatus = z.object({message: z.string().optional(), status: z.string().optional()}); export const v1alpha1InfoItem = z.object({name: z.string().optional(), value: z.string().optional()}); export const v1LoadBalancerIngress = z.object({hostname: z.string().optional(), ip: z.string().optional()}); export const v1alpha1ResourceRef = z.object({group: z.string().optional(), kind: z.string().optional(), name: z.string().optional(), namespace: z.string().optional(), uid: z.string().optional(), version: z.string().optional()}); export const v1alpha1ResourceNetworkingInfo = z.object({externalURLs: z.array(z.string()).optional(), ingress: z.array(v1LoadBalancerIngress).optional(), labels: z.record(z.string(), z.string()).optional(), targetLabels: z.record(z.string(), z.string()).optional(), targetRefs: z.array(v1alpha1ResourceRef).optional()}); export const v1alpha1ResourceNode = z.object({health: v1alpha1HealthStatus.optional(), images: z.array(z.string()).optional(), info: z.array(v1alpha1InfoItem).optional(), networkingInfo: v1alpha1ResourceNetworkingInfo.optional(), parentRefs: z.array(v1alpha1ResourceRef).optional(), resourceRef: v1alpha1ResourceRef.optional(), resourceVersion: z.string().optional()}); export const v1alpha1ApplicationTree = z.object({nodes: z.array(v1alpha1ResourceNode).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 /api/v1/applications/{applicationName}/resource-tree */ export const getApiApiV1ApplicationsApplicationNameResourceTree = async (args: GetApiApiV1ApplicationsApplicationNameResourceTreeArgs, options: GetApiApiV1ApplicationsApplicationNameResourceTreeOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/applications/${encodeURIComponent(String(args.applicationName))}/resource-tree${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(v1alpha1ApplicationTree, await res.json()) };