import {z} from 'zod' export type GetApiApiV1AddonsArgs = {registry?: string | undefined, query?: string | undefined}; export type GetApiApiV1AddonsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const addonDependency = z.object({name: z.string().optional(), version: z.string().optional()}); export const addonDeployTo = z.object({disableControlPlane: z.boolean(), runtimeCluster: z.boolean(), runtime_cluster: z.boolean().optional()}); export const addonSystemRequirements = z.object({kubernetes: z.string().optional(), vela: z.string().optional()}); export const addonMeta = z.object({annotations: z.record(z.string(), z.string()).optional(), dependencies: z.array(addonDependency).optional(), deployTo: addonDeployTo.optional(), description: z.string(), icon: z.string(), invisible: z.boolean(), name: z.string(), needNamespace: z.array(z.string()).optional(), system: addonSystemRequirements.optional(), tags: z.array(z.string()).optional(), url: z.string().optional(), uxPlugins: z.record(z.string(), z.string()).optional(), version: z.string()}); export const v1AddonInfo = z.object({Meta: addonMeta, registryName: z.string()}); export const v1ListAddonResponse = z.object({addons: z.array(v1AddonInfo), message: z.string().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 all addons * * GET /api/v1/addons */ export const getApiApiV1Addons = async (args: GetApiApiV1AddonsArgs, options: GetApiApiV1AddonsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.registry != null) query.append("registry", String(args.registry)) if (args.query != null) query.append("query", String(args.query)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/addons${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(v1ListAddonResponse, await res.json()) };