import {z} from 'zod' export type GetApiApiV1RepositoryChartValuesArgs = {project: string, chart: string, version: string, repoUrl: string, repoType: string, secretName?: string | undefined}; export type GetApiApiV1RepositoryChartValuesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiApiV1RepositoryChartValuesResponse = 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 }; /** * get chart value * * GET /api/v1/repository/chart/values */ export const getApiApiV1RepositoryChartValues = async (args: GetApiApiV1RepositoryChartValuesArgs, options: GetApiApiV1RepositoryChartValuesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.project != null) query.append("project", String(args.project)) if (args.chart != null) query.append("chart", String(args.chart)) if (args.version != null) query.append("version", String(args.version)) if (args.repoUrl != null) query.append("repoUrl", String(args.repoUrl)) if (args.repoType != null) query.append("repoType", String(args.repoType)) if (args.secretName != null) query.append("secretName", String(args.secretName)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/repository/chart/values${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(getApiApiV1RepositoryChartValuesResponse, await res.json()) };