import {z} from 'zod' export type AddonGitAddonSource = {path?: string | undefined, token?: string | undefined, tokenSecretRef?: string | undefined, url?: string | undefined}; export type AddonGiteeAddonSource = {path?: string | undefined, token?: string | undefined, tokenSecretRef?: string | undefined, url?: string | undefined}; export type AddonGitlabAddonSource = {path?: string | undefined, repo?: string | undefined, token?: string | undefined, tokenSecretRef?: string | undefined, url?: string | undefined}; export type AddonHelmSource = {insecureSkipTLS?: boolean | undefined, password?: string | undefined, token?: string | undefined, tokenSecretRef?: string | undefined, url?: string | undefined, username?: string | undefined}; export type AddonOSSAddonSource = {bucket: string, end_point: string, path: string}; export type V1UpdateAddonRegistryRequest = {git?: AddonGitAddonSource | undefined, gitee?: AddonGiteeAddonSource | undefined, gitlab?: AddonGitlabAddonSource | undefined, helm?: AddonHelmSource | undefined, oss?: AddonOSSAddonSource | undefined}; export type UpdateApiApiV1AddonRegistriesAddonRegNameArgs = {addonRegName: string, body: V1UpdateAddonRegistryRequest}; export type UpdateApiApiV1AddonRegistriesAddonRegNameOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const addonGitAddonSource = z.object({path: z.string().optional(), token: z.string().optional(), tokenSecretRef: z.string().optional(), url: z.string().optional()}); export const addonGiteeAddonSource = z.object({path: z.string().optional(), token: z.string().optional(), tokenSecretRef: z.string().optional(), url: z.string().optional()}); export const addonGitlabAddonSource = z.object({path: z.string().optional(), repo: z.string().optional(), token: z.string().optional(), tokenSecretRef: z.string().optional(), url: z.string().optional()}); export const addonHelmSource = z.object({insecureSkipTLS: z.boolean().optional(), password: z.string().optional(), token: z.string().optional(), tokenSecretRef: z.string().optional(), url: z.string().optional(), username: z.string().optional()}); export const addonOSSAddonSource = z.object({bucket: z.string(), end_point: z.string(), path: z.string()}); export const v1AddonRegistry = z.object({git: addonGitAddonSource.optional(), gitee: addonGiteeAddonSource.optional(), gitlab: addonGitlabAddonSource.optional(), helm: addonHelmSource.optional(), name: z.string(), oss: addonOSSAddonSource.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 }; /** * update an addon registry * * PUT /api/v1/addon_registries/{addonRegName} */ export const updateApiApiV1AddonRegistriesAddonRegName = async (args: UpdateApiApiV1AddonRegistriesAddonRegNameArgs, options: UpdateApiApiV1AddonRegistriesAddonRegNameOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/addon_registries/${encodeURIComponent(String(args.addonRegName))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(v1AddonRegistry, await res.json()) };