import {z} from 'zod' export type UpdateApiCodebasesCodebaseIdArgs = {codebaseId: string, body: {label?: string | undefined, description?: string | undefined}}; export type UpdateApiCodebasesCodebaseIdOptions = {baseUrl: string, CodebaseServiceAPIBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const codebaseServiceAPIHalLink = z.object({href: z.union([z.string(), z.string()]), templated: z.boolean().optional(), type: z.string().optional(), deprecation: z.string().optional(), name: z.string().optional(), profile: z.string().optional(), title: z.string().optional(), hreflang: z.string().optional()}); export const updateApiCodebasesCodebaseIdResponse = z.object({_links: z.object({self: codebaseServiceAPIHalLink}).and(z.record(z.string(), codebaseServiceAPIHalLink)), _embedded: z.record(z.string(), z.unknown()).optional(), message: z.literal("Codebase updated.")}); 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 }; /** * Updates a codebase by its ID. * * PUT /codebases/{codebaseId} */ export const updateApiCodebasesCodebaseId = async (args: UpdateApiCodebasesCodebaseIdArgs, options: UpdateApiCodebasesCodebaseIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, CodebaseServiceAPIBearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/hal+json") if (CodebaseServiceAPIBearerAuth !== undefined) headers.set('authorization', `Bearer ${CodebaseServiceAPIBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/codebases/${encodeURIComponent(String(args.codebaseId))}${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(updateApiCodebasesCodebaseIdResponse, await res.json()) };