import {z} from 'zod' export type GetApiApiV1ManagePluginsPluginIdArgs = {pluginId: string}; export type GetApiApiV1ManagePluginsPluginIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const typesKubernetesSecret = z.object({name: z.string(), namespace: z.string()}); export const typesKubernetesService = z.object({name: z.string(), namespace: z.string(), port: z.number().int()}); export const typesPermission = z.object({action: z.string(), resource: z.string()}); export const typesWorkspace = z.object({name: z.string()}); export const typesIncludes = z.object({catalog: z.string().optional(), icon: z.string(), label: z.string(), name: z.string(), permission: typesPermission.optional(), relatedRoute: z.array(z.string()), to: z.string(), type: z.string(), workspace: typesWorkspace}); export const typesInfoLink = z.object({name: z.string(), url: z.string()}); export const typesBuildInfo = z.object({branch: z.string().optional(), hash: z.string().optional(), repo: z.string().optional(), time: z.number().int().optional()}); export const typesLogos = z.object({large: z.string(), small: z.string()}); export const typesScreenshots = z.object({name: z.string(), path: z.string()}); export const typesInfo = z.object({author: typesInfoLink, build: typesBuildInfo, description: z.string(), links: z.array(typesInfoLink), logos: typesLogos, screenshots: z.array(typesScreenshots), updated: z.string(), version: z.string()}); export const v1PolicyRule = z.object({apiGroups: z.array(z.string()).optional(), nonResourceURLs: z.array(z.string()).optional(), resourceNames: z.array(z.string()).optional(), resources: z.array(z.string()).optional(), verbs: z.array(z.string())}); export const typesRequirement = z.object({velauxVersion: z.string()}); export const typesHeader = z.object({name: z.string(), value: z.string()}); export const typesRoute = z.object({headers: z.array(typesHeader).optional(), method: z.string(), path: z.string(), permission: typesPermission.optional(), resourceMap: z.record(z.string(), z.string()).optional()}); export const v1ManagedPluginDTO = z.object({authSecret: typesKubernetesSecret.optional(), authType: z.string().optional(), backend: z.boolean(), backendService: typesKubernetesService, backendType: z.string(), baseURL: z.string(), category: z.string(), class: z.string(), defaultNavURL: z.string(), enabled: z.boolean(), id: z.string(), includes: z.array(typesIncludes), info: typesInfo, jsonSetting: z.object({}), kubePermissions: z.array(v1PolicyRule).optional(), module: z.string(), name: z.string(), proxy: z.boolean(), requirement: typesRequirement.optional(), routes: z.array(typesRoute).optional(), secureJsonFields: z.record(z.string(), z.boolean()), subType: z.string(), type: z.string()}); 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 }; /** * Detail an installed plugin * * GET /api/v1/manage/plugins/{pluginId} */ export const getApiApiV1ManagePluginsPluginId = async (args: GetApiApiV1ManagePluginsPluginIdArgs, options: GetApiApiV1ManagePluginsPluginIdOptions) => { 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/manage/plugins/${encodeURIComponent(String(args.pluginId))}${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(v1ManagedPluginDTO, await res.json()) };